跟随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