我继承了mongodb系统的node.js。
原始开发者使用自己的帐户使用了mlab数据库,要求我复制到其他数据库。
当我尝试创建mlab用户时,我被重定向到cloud.mongodb.com(显然是在购买mlab)
我正在努力创建数据库并通过robo 3t
和Compass
连接到数据库,现在我可以连接和查询数据库。
我使用Compass导出/导入集合来复制数据库(无法以任何其他方式复制)
现在我将应用程序中的数据库uri设置为新的数据库,但是当我找到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.
这是我尝试连接外壳时得到的信息(请参见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
答案 0 :(得分:0)
正确的uri是
mongodb+srv://root:password@cluster0-jjbdh.mongodb.net/somebuddy?retryWrites=true
实际上几乎是地图集建议的uri:
mongodb+srv://root:<password>@cluster0-jjbdh.mongodb.net/test?retryWrites=true