1 year ago
#385216
phuongnam
Update MongoDB success in one process but can not find result on DB?
I use mongoengine to connect and query to mongodb. In init, I create a connection to the db. After that, i create an instance and do some operator with db. The result of these ops is shown in termial that run the code. But when i check by mongo shell, it show nothing. How can it happen?
I check that when i create an instance of Model, there are 2 connections created. I can not find a document explaining it.
file model.py
class Model():
def __init__(self):
self.db = connect(
db=cfg.database.db,
host=cfg.database.host,
port=cfg.database.port,
username=cfg.database.username,
password=cfg.database.password,
authentication_source='admin',
alias=alias
)
file main.py
from model import Model
model = Model()
# insert db ...
# get object ...
result show here: ...
code to insert and get result
def add(self, cid, result):
for o_id, r in result.items():
ObjectInfo.objects(cid=cid, o_id=o_id).update(
push__r=r.tolist(),
set__updatedAt=datetime.now(timezone('UTC')),
upsert=True
)
return
def get(self, cid):
return ObjectInfo.objects(cid=cid)
there are currently 3 connections, including itself when init Model
python
mongodb
connection
mongoengine
0 Answers
Your Answer