Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js authSource在mongo数据库url中的含义是什么?_Node.js_Mongodb_Robo3t - Fatal编程技术网

Node.js authSource在mongo数据库url中的含义是什么?

Node.js authSource在mongo数据库url中的含义是什么?,node.js,mongodb,robo3t,Node.js,Mongodb,Robo3t,我正在尝试使用以下连接字符串连接到我的mongo数据库 var Mongo_url = 'mongodb://MyUSer:tech@localhost:27017/chatme?authSource=admin'; 我得到的错误是 assertionError: null == { [MongoError: Authentication failed.] name: 'MongoError', message: 'Authentication failed.', ok: 0,

我正在尝试使用以下连接字符串连接到我的mongo数据库

var Mongo_url = 'mongodb://MyUSer:tech@localhost:27017/chatme?authSource=admin';  
我得到的错误是

 assertionError: null == { [MongoError: Authentication failed.]
 name: 'MongoError',
 message: 'Authentication failed.',
 ok: 0,
 code: 18,

有人能帮我清除这个“authSource=admin”吗。

这是拥有用户凭据的集合的数据库的名称


这是设置用户名和密码的地方。

我今天花了几个小时试图解决这个问题,不幸的是,这篇文章没有出现在我的搜索中。这太糟糕了,因为这是一篇回答这个问题最好的帖子

我希望通过添加我收到的错误消息来帮助下一个人

我正在Docker容器内设置连接,该容器通过Docker compose yaml文件旋转。用户名和密码从.env文件传递到docker compose中

有效的连接URI

mongodb://aUser:aPassword@mevn-app-mongo:27017/myDb?authSource=admin
错误:

SASL SCRAM-SHA-1 authentication failed for aUser on myDb from client 172.25.0.3:37352 ; UserNotFound: Could not find user aUser@myDb

我在system.users集合中有我的用户。因此,根据您的说法,“authSource=admin”应该替换为authSource=users。对吗?不,这是数据库的名称,不是集合的名称。它默认为您尝试连接的数据库。它在没有参数的情况下工作吗?是的,它也在没有参数的情况下工作。我现在明白了。ThanksI在使用非URL编码的连接SRV Strings时出现此错误在我的示例中,我试图以“root”身份登录到特定的数据库,但身份验证失败。将“authSource=admin”添加到连接字符串的末尾修复了它,谢谢!