Pymodm 连接到 mlab MongoDB

Pymodm connect to an mlab MongoDB

我有一个 MongoDB 数据库托管在 mlab 上,我想使用 PyMODM 作为我的对象建模库。

到目前为止,这是我的代码:

from pymodm import connect, MongoModel, fields


connect = connect('mongodb://user:pass@ds119788.mlab.com/db')

class Test(MongoModel):
    user = fields.CharField()


if __name__ == "__main__":
    test = Test("test")
    test.save()

但是它给了我这个错误:

pymongo.errors.ServerSelectionTimeoutError: ds119788.mlab.com:27017: [Errno 61] Connection refused

我错过了什么吗?

您需要使用 MongoDB URI provided by mlab for your account. The URI should contain the port 号码连接。

例如,它应该看起来像:

connect = connect('mongodb://user:password@ds119788.mlab.com:63123/databaseName')