SQL Server Vs MongoDB : Speed test?

10,095

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");

You wouldn't want to do this on every call though since it is another call to the DB and will have a very tiny performance hit.

Share:
10,095
Rawhi
Author by

Rawhi

Updated on June 04, 2022

Comments

  • Rawhi
    Rawhi almost 2 years

    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'");
    

    the MongoDB contains 1000000 record which are the same in the SQL .
    the data stored as the following:

    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

    Should I do anything to fix this !! because the mongo was always faster except this test !?!

  • Rawhi
    Rawhi over 13 years
    yes this is in the mongo console, but what about the c# driver !!
  • James Avery
    James Avery over 13 years
    Added how to do it through the C# driver - although you only need to do this once per database so I wouldn't call it every time.
  • Storm
    Storm almost 13 years
    @Rawhi: so what were your stats after ensureIndex() ?