如何使用 flask-mongoengine 连接 cosmosDB
How to connect cosmosDB using flask-mongoengine
我想使用 flask-mongoengine 库访问我的 azure cosmosDB 数据库。
我试图在 app.config['MONGODB_HOST'] 中传递主机 uri,但它从数据库集合返回空列表。
db= MongoEngine()
app.config['MONGODB_DB'] = 'DB_NAME'
app.config['MONGODB_HOST'] = 'mongodb://<username>:<password>@host:port/?ssl=true&replicaSet=replicaSetName'
db.init_app(app)
app.run(port=4001, debug=True)
打印 UserModel.objects(username=username) 时显示空列表。
P.S。我的数据库有 UserModel,它存储用户的用户名和密码。
我能够通过在 URI 中传递 database_name 而不是在 app.config
中传递来解决它
以下对我有用:
app.config['MONGODB_HOST'] = 'mongodb://<username>:<password>@host:port/DB_NAME?ssl=true&replicaSet=replicaSetName'
我想使用 flask-mongoengine 库访问我的 azure cosmosDB 数据库。
我试图在 app.config['MONGODB_HOST'] 中传递主机 uri,但它从数据库集合返回空列表。
db= MongoEngine()
app.config['MONGODB_DB'] = 'DB_NAME'
app.config['MONGODB_HOST'] = 'mongodb://<username>:<password>@host:port/?ssl=true&replicaSet=replicaSetName'
db.init_app(app)
app.run(port=4001, debug=True)
打印 UserModel.objects(username=username) 时显示空列表。
P.S。我的数据库有 UserModel,它存储用户的用户名和密码。
我能够通过在 URI 中传递 database_name 而不是在 app.config
中传递来解决它以下对我有用:
app.config['MONGODB_HOST'] = 'mongodb://<username>:<password>@host:port/DB_NAME?ssl=true&replicaSet=replicaSetName'