fluent-mongo icon indicating copy to clipboard operation
fluent-mongo copied to clipboard

How to get raw mongo query, that is sent to MongoDB server

Open mvreg opened this issue 13 years ago • 8 comments

When running my application I have to to write to screen raw query used.

Is any method/extension method available, to get from this:

IQueryable<EventsReceiver> alldata = hr.GetCollection<EventsReceiver>"EventsReceiver").AsQueryable().Where(q => q.UserId == "123");

something similar to: db.EventsReceiver.find({ "userid" : "123" });

Regards Damir

mvreg avatar Nov 14 '11 18:11 mvreg

var queryObject = ((IMongoQueryable)alldata).GetQueryObject();

this should give you back the object used to generate the query.

craiggwilson avatar Nov 16 '11 21:11 craiggwilson

Thx for reply.

Could be maybe IMongoQueryable marked as "non internal" in future versions it there are no further consequences of this change?

I'm currently getting: "Cannot access internal interface IMongoQueryable here" and 'FluentMongo.Linq.IMongoQueryable' is inaccessible due to its protection level.

Using FluentMongo 1.2.0.1. / Official MOngoDB c# driver 1.2

Regards

mvreg avatar Nov 17 '11 14:11 mvreg

Perhaps, or I'll find some other way of getting this out to you.

craiggwilson avatar Nov 17 '11 15:11 craiggwilson

In the meantime, you can do this yourself and compile the code up.

craiggwilson avatar Nov 17 '11 15:11 craiggwilson

+1 for this one. While linq abstracts all boring stuff, I would like to be able to debug some queries to see (or verify) that the correct "mongo query" is used behind the scenes.

RobThree avatar Nov 25 '11 10:11 RobThree

You can always see the actual query on the server by setting the profile-level.

Goffen avatar Nov 25 '11 11:11 Goffen

Maybe you guys can use log4net and enable "debug mode" via app.config. This way the client application will not be aware about all those dependencies. The only problem is that the project will depend upon log4net. I dont see this as problem.

ti24horas avatar Dec 23 '11 18:12 ti24horas

Something along these lines would be helpful also for generating IMongoQuery for removing items.

jberd126 avatar Jan 11 '12 07:01 jberd126