1

Possible Duplicate:
Translate Queryable<T> back to IMongoQuery

I want to see queries that is constructed by linq in MongoDB. I have been checked documentations about profiling but i couldn't find an information about this. system.profile table does not provide information enough about executed queries.

For example

I want to see native NoSql MongoDb query that is constructed by below query.

var col = Queryable.Where(o => o.Id == id).Select(o => o.Definitions.Take(10));

I tried to get query text as suggested in forums like below

var queryText = (col as MongoQueryable<IEnumerable<Definition>>).GetMongoQuery().ToJson();

// queryText = "{ \"_id\" : ObjectId(\"503376c0e1e28f09449b64d6\") }"

As you have seen queryText is not query that i am looking for.

How can i see queries via official .net driver or MongoDB profiling tools ?

Community
  • 1
  • 1
Freshblood
  • 6,285
  • 10
  • 59
  • 96
  • Please specify reason of down vote so i can make it clear question for you – Freshblood Aug 20 '12 at 19:45
  • This is a the same question as [Translate Queryable back to IMongoQuery](http://stackoverflow.com/questions/10261156/translate-queryablet-back-to-imongoquery). Accepted answer: You have to downcast the IQueryable to a MongoQueryable to get access to the GetMongoQuery() method. – Stennie Aug 21 '12 at 06:55
  • @Stennie Even that couldn't provide me constructed query in that way .. sadd. Have you really tried it ? – Freshblood Aug 21 '12 at 11:14
  • Not clear what output you are looking for, but that is what is supported by the current MongoDB .NET driver for LINQ queries. You could also convert to JSON with GetMongoQuery().ToJson() (related post on [mongodb-user](https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/ajU_p4aZIlA)). Similarly, the MongoDB [database profiler](http://www.mongodb.org/display/DOCS/Database+Profiler) includes information on all recent queries if you use `db.setProfilingLevel(2)`. You mention the system.profile doesn't provide enough information, but haven't included specific details on what you want. – Stennie Aug 21 '12 at 15:16
  • @Stennie I have provided more detail in my question now. I have been set setProfilinglevel but query property of profiling document does not contain query text. – Freshblood Aug 21 '12 at 16:06
  • Can't you see your queries in the log as well? – cirrus Aug 22 '12 at 11:58
  • @cirrus - Yes i can not see if you talk about system.profile collection – Freshblood Aug 22 '12 at 17:13

0 Answers0