1
考虑以下代码输出时间为3056
(约3秒)。性能差
因此,我使用MongoDb文档推荐的代码。
MongoClient mongo = new MongoClient();
var server = mongo.GetServer();
MongoDatabase db = server.GetDatabase("tutorial");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (server.RequestStart(db))
{
MongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("books");
for (int i = 0; i < 100000; i++)
{
var nested = new BsonDocument
{
{"name", "John Doe"},
};
collection.Insert(nested);
}
}
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds);
Console.ReadLine();
当上述代码运行的输出时间是14225
(大约10至14秒我的PC上)。 为什么我在新版本的mongoDb上重构代码后得到这样的性能时间。我错过了什么?
这正是我正在寻找与WriteConcern.Unacknowledged集我得到同样的performance.thank你。 –