首页 > 解决方案 > 如何使用 Jupyter 笔记本从 Watson Studio 连接到 MongoDB

问题描述

我想使用 Python 环境从 watson studio 连接到 MongoDB,我尝试了下面的代码

MONGO_HOST = "xxxxxxxxx" # hostname
MONGO_PORT = 30325
MONGO_DB = "test"
MONGO_USER = "xxxx"
MONGO_PASS = "xxxxxxxx"
con = pymongo.MongoClient(MONGO_HOST, MONGO_PORT)
db = con[MONGO_DB]
db.authenticate(MONGO_USER, MONGO_PASS)

然后我得到了这个错误: ServerSelectionTimeoutError: connection closed,connection closed,connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 60c72c0d8b3ca9554ba1ba19, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('hostname', 30325) server_type: Unknown, rtt:无,错误=AutoReconnect('连接关闭')>,<ServerDescription('80eef57e-dc80-47b1-a0bc-0b674d206d21-1.c0v4phir0ah9ul9trho0.databases.appdomain.cloud',30325)server_type:未知,rtt:无, error=AutoReconnect('connection closed')>, <ServerDescription ('hostname', 30325) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>]>

标签: pythonmongodbjupyter-notebookibm-cloudwatson-studio

解决方案


推荐阅读