Mongodb 中的服务器连接

本文关键字:连接 服务器 Mongodb | 更新日期: 2023-09-27 18:33:17

我有一个安装了Mongodb 64位的远程服务器,并让mongod运行。我正在测试在家中连接它。使用以下连接字符串 C#:

connectionString = "mongodb://Administrator:mypassword@x.x.x.x:27017"

连接失败,出现以下错误:

Unable to connect to server x.x.x.x:27017: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond x.x.x.x:27017

我需要在服务器上进行配置吗?还是在我的连接字符串中?

Mongodb 中的服务器连接

我也无法使用连接字符串连接到远程MongoDB。我让它工作的方式有点冗长,但假设你试图这样做

var client = new MongoClient(connectionString);

那么这可以代替:

var client = new MongoClient(
new MongoClientSettings
{
 Credentials = new[]
 {
   MongoCredential.CreateCredential("Databasename","Administrator", "mypassword")
 },
 Server = new MongoServerAddress("x.x.x.x", 27017)
});

我已经通过绑定解决了这个问题

bind_ip = 0.0.0.0