2017-02-26 54 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