我尝试从Mongo 2.0驱动程序初始化MongoClient,如下所示:
MongoClientSettings settings = new MongoClientSettings();
settings.WaitQueueSize = int.MaxValue;
settings.WaitQueueuTimeout = new TimeSpan(0,2,0);
settings.MinConnectionPoolSize = 1;
settings.MaxConnectionPoolSize = 25;
settings.Server = new MongoServerAddress("mongodb://localhost");
client = new MongoClient(settings)
但是,当我现在尝试使用以下代码插入文档时:
db = client.GetDatabase("local");
col = db.GetCollection<BsonDocument>(collectionName);
col.InsertOneAsync(new BsonDocument().Add(new BsonElement("id",BsonValue.Create(1)))).Wait();
它没有做任何事情。它没有插入,也没有错误消息(虽然一段时间后输出中出现System.Timeout的第一次机会异常)。如果我用
初始化客户端client = new MongoClient("mongodb://localhost")
它可以正常工作并按预期上传文档。
我希望客户端能够处理非常高的写入吞吐量,所以我首先尝试了这些设置。我是否设置了一些错误设置或是否存在其他问题?
编辑:经过一些更多的测试,它确实是我收到的System.Timeout异常。答案 0 :(得分:10)
我可以重现这个问题,只有在我的错误信息中,有一些更有用的信息埋在大约40行文本中:
没有这样的主人知道
事实证明MongoServerAddress
only expects the hostname, not the protocol:
settings.Server = new MongoServerAddress("localhost");