SQL Server Vs MongoDB: Speed ​​Test?

Possible duplicate:
mongoDB runs queries in the same way as SQL !!!

MongoDB:

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

SQL:

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

MongoDB contains 1,000,000 records that are the same in SQL.
data is stored as follows:

Id = 1 , _Data = 1abc
Id = 2 , _Data = 2bc 
... etc

Event class:

Class Event => int Id => string _Data 

when I run the code, the result is: Mongo: 580ms
SQL: 102ms

Do I have to do anything to fix this! because mongo has always been faster than this test !?

thank

+3
source share
1 answer

You need an index. Run this in the mongo console:

db.Events.ensureIndex({_Data:1});

or you can call it through the C # driver:

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

, , .

+5

Source: https://habr.com/ru/post/1787430/


All Articles