简体   繁体   中英

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM