Mongodb中的服务器连接

问题描述 投票:1回答:2

我有一台安装了Mongodb 64位的远程服务器,并使mongod处于运行状态。 我正在测试从家里连接它。 使用以下连接字符串C#:

connectionString = "mongodb://Administrator:[email protected]: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

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

c# mongodb
2个回答
0
投票

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

bind_ip = 0.0.0.0

0
投票

我也无法使用连接字符串连接到远程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)
});
© www.soinside.com 2019 - 2024. All rights reserved.