2017-02-26 67 views
0

跟随Document关于如何连接到本地主机。 MongodDB Compass可以连接到“localhost:27017”,没有身份验证,没有SSL,没有SSH隧道。在C#项目,试图连接字符串'mongodb // localhost'无效

mongodb//localhost 
mongodb//localhost:27017 
localhost:27017 

都得到同样的

MongoDB.Driver.MongoConfigurationException了未处理
的HResult = -2146233088消息=连接字符串 '全上面' 不是 有效。源= MongoDB.Driver.Core堆栈跟踪: 在MongoDB.Driver.Core.Configuration.ConnectionString.Parse() 在MongoDB.Driver.Core.Configuration.ConnectionString..ctor(字符串 的connectionString) 在MongoDB.Driver.MongoUrlBuilder .Parse(字符串URL) 在MongoDB.Driver.MongoUrl..ctor(字符串URL) 在MongoDB.Driver.MongoClient..ctor(字符串的connectionString)

下面是代码:

static string con = "mongodb//localhost"; 
MongoClient mclient = new MongoClient(con); 

MongoDB.Driver v2.4.2,MongoDB.Driver.Core v 2.4.2

怎么了?

+1

你错过了':'分隔符。可能你也需要端口。改为'“mongodb:// localhost:27017”'More here http://mongodb.github.io/mongo-csharp-driver/2.4/reference/driver/connecting/#connection-string – Veeram

+0

@Veeram你是对的。我知道一定有一些愚蠢的东西。谢谢 – Jeb50

回答

1
  • 的 “:” 之后MongoDB的失踪。
  • 如果你在默认端口上运行,只需要mongodb:// localhost 就可以完成这项工作。
  • 在如果您有它配置到其他端口或蒙戈服务器的情况是 在网络中的不同服务器上运行的格式看起来是 这样的:的MongoDB://192.168.0.xx:27017