本文介绍了MongoEngine-另一个用户已通过此数据库验证.您必须先注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释我为什么出现错误另一个用户已经通过此数据库验证.使用 Flask MongoEngine 连接到MongoDB时,您必须先注销?

Can anyone please explain why I am getting error Another user is already authenticated to this database. You must logout first when connecting to MongoDB using Flask MongoEngine?

from mongoengine.connection import get_db
from flask import Flask, jsonify, abort
from flask_cors import CORS
from flask_mongoengine import MongoEngine
from flask_restful import Api

def init_db():
    return MongoEngine()

app = Flask(__name__)
CORS(app)
api = Api(app)
app.config.from_object('conf.settings')
db = init_db()
db.init_app(app)

@app.route('/health_check')
def on_health_check():
    try:
        db = get_db()
        db.command('dbstats')

        return jsonify(
            status=200
        )
    except Exception as e:
        logging.exception('on_health_check() exception -> {}'.format(str(e)))
        abort(500, 'Could not connect to database')


app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)

conf/settings.py:

conf/settings.py:

MONGODB_SETTINGS = {
    'host': 'mongodb://username:password@mongo-rep-mongodb-replicaset-0.local:27017,mongo-rep-mongodb-replicaset-1.local:27017/db_name?replicaSet=whatever'
}

当我转到http://localhost:5000/health_check时,它总是将Exception随消息一起抛出,如上所述.

When I go to http://localhost:5000/health_check, it always throws the Exception with message as I described above.

推荐答案

所以我今天遇到了同样的问题,但最终通过安装pymongo的先前版本来解决此问题,例如pip install pymongo == 3.4.0而不是最新版本3.7.0.可能有一个错误...

So I was running into the same issue today, but ended up resolving it by installing a previous version of pymongo, e.g. pip install pymongo==3.4.0 instead of the latest version 3.7.0. There might be a bug...

这篇关于MongoEngine-另一个用户已通过此数据库验证.您必须先注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 20:37