如何在mongodb连接字符串中使用身份验证指定我的dbName?

时间:2017-11-10 03:00:03

标签: mongodb

在我的express / mongoose应用程序中,假设我在同一个mongodb服务器中有多个dbs,一个是xxx。如果我没有认证,我的连接字符串看起来像

QTextCodec *codec1 = QTextCodec::codecForName("Shift-JIS");
QByteArray encoded = "81ff"; 
QString current = codec->toUnicode(QByteArray::fromHex(encoded));
ui->hientai->setText(current);

效果很好。现在,我将身份验证添加为

mongodb://myserver.cloudappserver.net/xxx

根据文档,我的连接字符串应该看起来像

use admin
db.createUser({user:"admin",pwd:"yyy",roles:[{role:"root",db:"admin"}]});

现在,我的问题是如何指定我想使用的db“xxx”?

1 个答案:

答案 0 :(得分:0)

我根据this计算出......连接字符串应该如下所示

mongodb://admin:yyy@myserver.cloudappserver.net/xxx?authSource=admin