I am not sure how to connect to a mongodb database that uses an authentication database with mongoengine.
On the command prompt I need to do mongo hostname:27017/myApp -u "test" -p "test" --authenticationDatabase admin
, but I don't see where I'd pass this as an argument to mongoengine so I use the admin database for auth but connect to the myApp database for my models?
I believe this is where it's explained in the PyMongo guide:
https://api.mongodb.com/python/current/examples/authentication.html
>>> from pymongo import MongoClient
>>> client = MongoClient('example.com')
>>> db = client.the_database
>>> db.authenticate('user', 'password', source='source_database')
and I found the pull request that added this to mongoengine:
https://github.com/MongoEngine/mongoengine/pull/590/files
It looks like you just add authentication_source
as an argument to connect
like connect(authentication_source='admin')
. It'd be nice if it was better documented.
http://docs.mongoengine.org/apireference.html?highlight=authentication_source