【发布时间】:2020-07-09 17:45:35
【问题描述】:
我正在使用 django 和 mongodb atlas 并尝试使用 heroku 进行部署。不知何故,我一直面临pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused 这个错误。
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'name',
'HOST': 'mongodb+srv://user:pass@cluster0-xb9zh.mongodb.net/test?retryWrites=true&w=majority',
'USER': 'user',
'PASSWORD': 'pass',
}
}
对于 django setting.py,我只是将其从 sqlite 更改为 mongodb。它在我当地完美运行。我怀疑有一个变化是我必须将 mongo_client.py 文件从 localhost 更改为连接字符串,以使我的 mongodb 连接到 atlas 而不是我的本地数据库。不知道这是否与此有关。
class MongoClient(common.BaseObject):
"""
A client-side representation of a MongoDB cluster.
Instances can represent either a standalone MongoDB server, a replica
set, or a sharded cluster. Instances of this class are responsible for
maintaining up-to-date state of the cluster, and possibly cache
resources related to this, including background threads for monitoring,
and connection pools.
"""
HOST = "mongodb+srv://user:pass@cluster0-xb9zh.mongodb.net/test?retryWrites=true&w=majority"
PORT = 27017
# Define order to retrieve options from ClientOptions for __repr__.
【问题讨论】:
标签: python django mongodb heroku