我在Windows Azure平台上的Linux服务器( 标准D2 v2(2核,7 GB内存) )中创建了MongoDB数据库。
我正在使用以下代码测试数据插入数据库。但结果并不好......! 47秒插入100.000记录非常糟糕。问题是什么?
插入mongodb的代码
string connectionString = "mongodb://root:bitnami@myserveraddress:27017";
var client = new MongoClient(connectionString);
var database = client.GetDatabase("testdb");
var collection = database.GetCollection<Item>("foo");
var documents = Enumerable.Range(1, 100000).Select(i => new Item
{
Address = "Address " + i,
City = "City " + i,
Index = i + 1,
Name = "Name " + i,
Status = i % 2 == 0,
Surname = "Surname " + i,
Title = "Title " + i,
Town = "Town " + i
});
var models = documents.Select(s => new InsertOneModel<Item>(s)).ToList();
Stopwatch sw = new Stopwatch();
sw.Start();
var result = collection.BulkWrite(models);
sw.Stop();
Console.WriteLine("Seconds:" + sw.Elapsed.Seconds);
result.InsertedCount.Dump();
collection.Count(p => 1 == 1).Dump();
答案 0 :(得分:0)
Azure上的我的数据文件(Linux虚拟机 - 标准D2 v2(2核,7 GB内存))