首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mongodb如何获取正确的uri

mongodb如何获取正确的uri
EN

Stack Overflow用户
提问于 2019-04-07 22:36:03
回答 1查看 8K关注 0票数 0

我继承了node.js,mongodb系统。

最初的开发人员在他自己的帐户上使用了mlab数据库,我被要求复制到另一个数据库。

当我试图创建一个mlab用户时,我被重定向到了cloud.mongodb.com (显然是购买了mlab)

我很难创建一个数据库并通过robo 3tCompass连接到它,现在我可以连接和查询数据库了。

我使用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 3tCompass上工作,所以我猜这只是一个例子。

我对以下内容感到厌烦

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):

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
.\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
EN

回答 1

Stack Overflow用户

发布于 2019-04-08 00:27:03

正确的uri是

mongodb+srv://root:password@cluster0-jjbdh.mongodb.net/somebuddy?retryWrites=true

这几乎就是atlas建议的uri:

mongodb+srv://root:<password>@cluster0-jjbdh.mongodb.net/test?retryWrites=true

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55560098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档