Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see mongoengine built query?

How can I print the mongodb query I buid with mongoengine? Example:

queryset = Document.objects(**query)
print queryset.to_mongodb_query()
like image 565
Italo Maia Avatar asked Mar 16 '15 05:03

Italo Maia


1 Answers

Yes. There is a .query accessor on the QuerySet. For example:

queryset = Document.objects(field__lte=5)
print queryset._query

Would produce:

{ "field": { "$lte": 5 } }

You can also call .explain() for descriptive output to the query execution statistics if you wanted that at another log level.

like image 55
Neil Lunn Avatar answered Nov 02 '22 03:11

Neil Lunn