Is there a way to see the executed queries on MongoDB? I enabled profiling through the mongo.exe on windows with the following command:
db.setProfilingLevel(2);
This enables profiling and I can query the profile data with the following command for example:
db.system.profile.find().limit(10).sort( { ts : -1 } ).pretty()
However, this doesn't get me the executed queries. I know that I can also use the IMongoQuery.ToJson()
method to see the query but I am using Linq queries with MongoDB C# Driver (BTW, I really wonder why they called this C# driver instead of .NET driver).
Here is the sample:
var people = db.GetCollection<Person>("People")
.AsQueryable().Where(x => x.Sessions.Any(y => y.SessionDate != null));
var peeps = people.Select(x =>
x.Sessions.Where(y => y.SessionDate != null)).ToList();
However, that would be really cool to be able to do the following:
var people = db.GetCollection<Person>("People")
.AsQueryable().Where(x => x.Sessions.Any(y => y.SessionDate != null))
.Expression.ToJson();
But this is not supported I guess. Any ideas?