【发布时间】:2019-08-28 19:35:08
【问题描述】:
我继承了node.js,mongodb系统。
原来的开发者在他自己的账户上使用了一个 mlab 数据库,我被要求复制到另一个数据库。
当我尝试创建 mlab 用户时,我被重定向到 cloud.mongodb.com(显然购买了 mlab)
我正在努力创建一个数据库并通过robo 3t 和Compass 连接到它,现在我可以连接和查询数据库了。
我使用 Compass 导出/导入集合来复制数据库(无法以任何其他方式复制)
现在我将应用程序中的 db uri 设置为新的 db,但是当我执行 findOne 时它挂起
这是旧的 uri:
mongodb://dekel:password@ds115094.mlab.com:15094/somebuddy
因此我假设连接字符串应该是:
mongodb://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/somebuddy
我明白了
UnhandledPromiseRejectionWarning: MongoNetworkError: connection 0 to cluster0-shard-00-00-jjbdh.mongodb.net:27017 closed
当我与robo 3t 连接时,我必须将数据库设置为admin,否则我会得到:Network is unreachable.
因此我尝试了以下
mongodb://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin
我明白了:
MongoNetworkError: connection 0 to cluster0-shard-00-00-jjbdh.mongodb.net:27017 closed
Mongodb 网站说连接字符串应该是
mongodb+srv://root:<password>@cluster0-shard-00-00-jjbdh.mongodb.net/test?retryWrites=true
这很奇怪,因为cluster0-shard-00-00-jjbdh.mongodb.net 不适用于robo 3t 和Compass,所以我想这只是一个例子。
我累了以下
mongodb+srv://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/somebuddy
我明白了:
Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-shard-00-00-jjbdh.mongodb.net
我尝试了以下不同的用户
当我尝试使用 mongodb 网站上的聊天时,我得到:
The team will get back to you on this. MongoDB Cloud Chat will be back tomorrow.
这是我尝试与 shell 连接时得到的结果(请参阅https://www.youtube.com/watch?v=Ej05tq1220A):
C:\Program Files\MongoDB\Server\4.0\bin> .\mongo.exe "mongodb+srv://cluster0-jjbdh.mongodb.net/test" --username root
MongoDB shell version v4.0.8
Enter password:
connecting to: mongodb://cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-04-07T19:03:46.945+0300 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017
2019-04-07T19:03:58.840+0300 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-04-07T19:03:58.841+0300 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2019-04-07T19:04:00.281+0300 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-04-07T19:04:00.282+0300 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
2019-04-07T19:04:01.751+0300 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-04-07T19:04:01.752+0300 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2019-04-07T19:04:01.756+0300 E QUERY [js] Error: connect failed to replica set Cluster0-shard-0/cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017 :
connect@src/mongo/shell/mongo.js:343:13
@(connect):2:6
exception: connect failed
和
.\mongo.exe "mongodb://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin"
MongoDB shell version v4.0.8
connecting to: mongodb://cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin?gssapiServiceName=mongodb
2019-04-07T19:17:19.420+0300 E QUERY [js] Error: network error while attempting to run command 'isMaster' on host 'cluster0-shard-00-00-jjbdh.mongodb.net:27017' :
connect@src/mongo/shell/mongo.js:343:13
@(connect):2:6
exception: connect failed
【问题讨论】:
-
我看到一个白名单标签,您是否将您的 IP 列入白名单?
-
是的。我做到了,我关注了stackoverflow.com/questions/43694799/…
标签: mongodb