skip to Main Content

Connect to MongoDB via python

I'm trying to connect to mongodb using python and code: myclient = pymongo.MongoClient("mongodb://root:password@mongo:27017/database_sample?authSource=admin") db = myclient.database_sample my_collection = db["database"] but I'm getting pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}

VIEW QUESTION

Mongodb – Use keys as variables in python

I'm trying to remove the keys from a mongoengine Document in python: document.update(unset__name=True) document.update(unset__surname=True) document.update(unset__dob=True) ... but instead of the above I would like to loop through them and use a variable, something like: document.update(unset__<key>=True) Is this possible?

VIEW QUESTION
Back To Top
Search