更新时间:2022-06-03 21:58:46
如果我不得不冒险猜测,那么该问题很可能是防火墙问题.您应该检查以下内容
If I had to hazard a guess, the issue is most likely a firewall issue. You should check the following
nslookup
ping
(可能会失败,具体取决于mLab的设置)telnet
(例如telnet ds048719.mlab.com 48719
authenticationDatabase
(在您的示例中,这是由/db
指定的),通常为admin
,但是如果您在共享实例上,则可以是您的数据库名称.nslookup
of the host (ds048719.mlab.com) from the C# Application Hostping
of the host (ds048719.mlab.com) from the C# Application Host (might fail, depending on mLab's settings)telnet
, eg telnet ds048719.mlab.com 48719
authenticationDatabase
(in your example, this is specified by the /db
), this is usually admin
but could be your database name if you are on a shared instance.You can find the docs on connecting with the C# driver in the MongoDB C# Driver Docs. It is important to note the following:
数据库组件
数据库组件是可选的,用于指示要针对哪个数据库进行身份验证.如果未提供数据库组件,则使用"admin"数据库.
The database component is optional and is used to indicate which database to authenticate against. When the database component is not provided, the "admin" database is used.
mongodb://host:27017/mydb
上面,名称为"mydb"的数据库是存储应用程序凭据的位置.
Above, the database by the name of "mydb" is where the credentials are stored for the application.
注意:
某些驱动程序利用数据库组件来指示默认情况下要使用的数据库. .NET驱动程序在解析数据库组件时,除了身份验证外,不将其用于其他任何用途.
Some drivers utilize the database component to indicate which database to work with by default. The .NET driver, while it parses the database component, does not use the database component for anything other than authentication.
最后,我建议将来在发布到SO时混淆主机名和端口.虽然仅靠模糊性来保证安全性是不好的策略,但它无疑为MongoDB部署增加了一层防御.
Finally, I would suggest in the future, obfuscate the hostname and port when posting to SO. While security through obscurity alone is a bad policy, it certainly adds a layer of defense for your MongoDB deployment.