NodeJS - MongoClient.Connect 带有到 DB 的 URL 而非默认值 [英] NodeJS - MongoClient.Connect with URL to DB Other Than Default

查看:43
本文介绍了NodeJS - MongoClient.Connect 带有到 DB 的 URL 而非默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 MongoClient.Connect(Url) 选项从 Node 进行连接,实际上它确实适用于到 admin 数据库的经过身份验证的连接.但是,如果我尝试指定不同的数据库,则会收到代码为 18 的身份验证失败".

I'd like to use the MongoClient.Connect(Url) option for connecting from Node and in fact it does work for authenticated connections to the admin database. However, if I try to specify a different database I get an "auth Fails" with code 18.

我认为这意味着凭据仅在管理数据库上设置,不幸的是,我无法更改这种安排(无论如何,目前).

I think this means that the credentials are only setup on the admin database and, unfortunately, I can't change this arrangement (for now, anyway).

这个 Url 语法似乎是驱动程序前进的方向,所以如果可能的话,我想使用它.有没有办法使用这种语法,进行身份验证并连接到 admin 数据库,然后连接到服务器上的其他数据库之一?

It seems this Url syntax is the direction the driver is heading, so I'd like to use it if possible. Is there a way to use this syntax, authenticate and connect to the admin database, and then get a connection to one of the other databases on the server?

推荐答案

我刚刚发现如何执行此操作:您使用获得的实例 ("admin") 打开另一个您有权访问的数据库:

I just found out how to do this: You use the instance you get ("admin") to open another database you have access to:

db2 = db.db("name of other name");

看到它隐藏在文档

这篇关于NodeJS - MongoClient.Connect 带有到 DB 的 URL 而非默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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