我继承了node.js,mongodb系统。
原来的开发人员在他自己的帐户上使用了一个mlab数据库,我被要求复制到一个不同的数据库。
When I tried to create a mlab user I was redirected to cloud.mongodb.com (which apparently purchase mlab)
创建一个数据库并通过robo 3t
和Compass
连接到它时,我感到很吃力,现在我能够连接和查询数据库了。
我使用Compass导出/导入集合复制数据库(无法以任何其他方式复制)
现在,我将应用程序中的dburi设置为新的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
1条答案
按热度按时间0sgqnhkj1#
正确的URI为
第一个月
其实际上几乎是Atlas所建议的URI:
mongodb+srv://root:<password>@cluster0-jjbdh.mongodb.net/test?retryWrites=true