How to see the query built on mongoengine?

How can I print the mongodb request that I earned with mongoengine? Example:

queryset = Document.objects(**query) print queryset.to_mongodb_query() 
+5
source share
1 answer

Yes. QuerySet has a .query accessor. For instance:

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

Will produce:

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

You can also call .explain() for descriptive output to query execution statistics if you want to log at a different level.

+9
source

Source: https://habr.com/ru/post/1215424/


All Articles