pymongo通过配置文件设置read_preferences连接

时间:2018-02-12 08:38:20

标签: mongodb pymongo mongoengine

ENVIRONMENT_CONFIG_FILE包含:

MONGODB_SETTINGS = {
    'host': 'localhost',
    'port': 27017,
    'db': 'my_db'
}

//in my application
app.config.from_envvar('ENVIRONMENT_CONFIG_FILE_LOCATION')

MongoEngine(app)

我想要设置read_prefrences,我可以在应用程序级别

中设置它
from pymongo import ReadPreference
app.config['MONGODB_SETTINGS']['read_prefrences'] = ReadPreference.PRIMARY
MongoEngine(app)

哪个会起作用,但我想在配置文件中设置read_preferences。我是如何做到这一点的,因为ReadPreference.PRIMARY不是string

0 个答案:

没有答案