使用SCRAM-SHA-1在猫鼬中进行身份验证 [英] Authentication in mongoose using SCRAM-SHA-1

查看:275
本文介绍了使用SCRAM-SHA-1在猫鼬中进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从MongoDB 2.6升级到了3.0.4,并且还将Mongoose版本升级到了4.0.0.

I recently upgraded from MongoDB 2.6 to 3.0.4 and also upgraded the Mongoose version to 4.0.0.

现在,当我尝试使用猫鼬连接到mongo时:

Now when ever i try to connect to mongo using mongoose:

mongoose.connect('mongodb://user:password@host:port/dbname')

在mongo日志上,我收到此消息

On mongo logs i receive this message

客户端上dbname上的用户的SCRAM-SHA-1身份验证失败 xxx.xxx.xxx.xxx

SCRAM-SHA-1 authentication failed for user on dbname from client xxx.xxx.xxx.xxx

我在mongodb中签入,该用户存在于admin中.我使用的命令是 db.system.users.findOne({user:'user'})

I checked in mongodb, the user exists in the admin. The command that i used is db.system.users.findOne({user:'user'})

此语句返回的信息包含SCRAM-SHA-1信息.

The information returned by this statement contains SCRAM-SHA-1 information.

我的问题是在建立连接时如何在猫鼬中指定SCRAM相关信息.我读了很多文章,但不了解它是如何完成的

My question is how to specify SCRAM related information in mongoose while establishing connection. I read lots of articles, but failed to understand how its done

推荐答案

找到解决方案,我没有传递authDatabase名称,这就是连接失败的原因.之前我在用这个

Found the solution, I didn't passed the authDatabase name, that's why the connection failed. Earlier i was using this

mongoose.connect('mongodb://user:password@host:port/dbname')

现在我用了这个

mongoose.connect('mongodb://user:password@host:port/dbname?authSource=dbWithUserCredentials')

在猫鼬本身的讨论线程上找到了该解决方案

Found this solution on Discussion thread of Mongoose itself

别忘了用您自己的内容替换dbWithUserCredentials.在大多数情况下,dbWithUserCredentials是admin.所有登录凭据(如用户名,密码)均已在传递给mongoose.connect()的参数中指定.

Don't forget to replace dbWithUserCredentials with your own. In most cases dbWithUserCredentials would be admin. All the credentials for login like username, password are already specified in the parameter passed to mongoose.connect().

这篇关于使用SCRAM-SHA-1在猫鼬中进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆