【发布时间】:2016-11-06 01:06:25
【问题描述】:
我不知道如何连接到使用带有 mongoengine 的身份验证数据库的 mongodb 数据库。
在命令提示符下,我需要执行 mongo hostname:27017/myApp -u "test" -p "test" --authenticationDatabase admin,但我看不到将其作为参数传递给 mongoengine 的位置,因此我使用 admin 数据库进行身份验证,但连接到 myApp 数据库以获取我的模型?
我相信这是 PyMongo 指南中解释的地方:
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')
我发现了将它添加到 mongoengine 的拉取请求:
https://github.com/MongoEngine/mongoengine/pull/590/files
看起来您只是将authentication_source 作为参数添加到connect,例如connect(authentication_source='admin')。如果有更好的文档记录就好了。
http://docs.mongoengine.org/apireference.html?highlight=authentication_source
【问题讨论】:
标签: python mongodb mongoengine