跟隨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
怎麼了?
你錯過了':'分隔符。可能你也需要端口。改爲'「mongodb:// localhost:27017」'More here http://mongodb.github.io/mongo-csharp-driver/2.4/reference/driver/connecting/#connection-string – Veeram
@Veeram你是對的。我知道一定有一些愚蠢的東西。謝謝 – Jeb50