简体   繁体   中英

Django mongoengine not connect to remote server, always connect to localhost

In django app, I try to set:

connect('db', host='user:pass@ec2-23-20-248-142.compute-1.amazonaws.com:47468')

but it always return:

MongoClient('localhost', 27017)

Have you tried 'URI style connections' like this one below?

_MONGODB_USER = MONGO_USER
_MONGODB_PASSWD = MONGO_PASSWD
_MONGODB_HOST = 'ec2-23-20-248-142.compute-1.amazonaws.com:47468'
_MONGODB_NAME = 'db'
_MONGODB_DATABASE_HOST = 'mongodb://%s:%s@%s/%s' % (_MONGODB_USER, _MONGODB_PASSWD, _MONGODB_HOST, _MONGODB_NAME)
 mongoengine.connect(_MONGODB_NAME, host=_MONGODB_DATABASE_HOST)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM