Reputation: 6413
public IQueryable<T> GetRecords<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression, int from, int first) where T : class, new()
{
first = first == 0 ? 30 : first;
return _db.GetCollection<T>(collectionName).Linq().Where(expression).Skip(from).Take(first);
}
var x = GetRecords<Event>(p => true, 0, 12222);
string eventJson = new JavaScriptSerializer().Serialize(x);
this function get the data from mongoDB.
SqlDataReader dr = SqlHelper.ExecuteReader("Select Top(12222)* From NewsFeed");
string eventJson = new JavaScriptSerializer().Serialize(dr);
and this from SQL Server .
I've tried to measure the execute time for each of them and the result was :
Mongo : 172ms
SQL : 185ms .
but as I know the mongoDB should be too much faster than SQL , right !?!
Upvotes: 2
Views: 2194
Reputation: 32575
MongoDB isn't necessarily about out-performing SQL server in a simple query like that; The speed advantage comes in when you have ancillary data. I don't know what your domain looks like, but a common example is a blog. In a SQL database, you would have a posts table, a comments table, an authors table, etc. Your query to retrieve all the data required for a single blog post display would either include a few joins or multiple queries (either way will affect the performance a bit). In a NoSQL database, there could be a single table, Posts. One query with no joins will pull back all required data.
Upvotes: 7