'How to retrieve Mongo query string from FindIterable (mongo java driver)

Is there a way to simply retrieve the query string that MongoDB java driver does? For example:

filter = eq("field","value");

FindIterable<BasicDBObject> find = collection.find(filter).projection(fields(include("field"), excludeId()));

When iterating, this should invoke the query :

db.collection.find({"field":"value"},{"field":1, "_id":0})

which will be split in batches, the first of which will be of 101 elements and next ones of max 16MB (but I don't really care about this. I just need the initial query). Is there a way to retrieve this string from the FindIterable or other objects of mongodb java driver?

I read elsewhere of people who were suggesting to do it from logging. I need the query string at runtime cause I have to use it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source