SQL Server与MongoDB:速度测试?

Raw*_*hi 3 c# linq sql-server performance mongodb

MongoDB的:

var x = nosql.GetRecords<Event>(p => p._Data == "rawhix", 0, 12222);
// ICursor<T> GetRecords<T>(expression, skip, limit);
Run Code Online (Sandbox Code Playgroud)

SQL:

SqlDataReader dr = SqlHelper.ExecuteReader("Select Top(12222)* From NewsFeed WHERE _Data = 'dddd'");
Run Code Online (Sandbox Code Playgroud)

MongoDB包含1000000条记录,这些记录在SQL中是相同的.
数据存储如下:

Id = 1 , _Data = 1abc
Id = 2 , _Data = 2bc 
... etc
Run Code Online (Sandbox Code Playgroud)

Event 课程:

Class Event => int Id => string _Data 
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,结果是:
Mongo:580ms
SQL:102ms

我应该做些什么来解决这个问题!因为除了这个测试,mongo总是更快!?!

Jam*_*ery 5

你需要一个索引.在mongo控制台中运行:

db.Events.ensureIndex({_Data:1});
Run Code Online (Sandbox Code Playgroud)

或者你可以通过C#驱动程序调用它:

MongoDatabase db = server.GetDatabase("your_db_name");
MongoCollection<Event> events = hr.GetCollection<Event>("events");
employees.EnsureIndex("_Data");
Run Code Online (Sandbox Code Playgroud)

你不希望在每次通话时都这样做,因为它是对DB的另一次调用,并且会有非常小的性能损失.