Django mongoengine没有连接到远程服务器,总是连接到localhost

时间:2015-11-28 16:15:19

标签: python django mongodb mongoengine

在django app中,我尝试设置:

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

但总是回归:

  

MongoClient('localhost',27017)

1 个答案:

答案 0 :(得分:-1)

您是否尝试过类似下面的“URI样式连接”?

_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)