问题
Starting with MongoDB 3.2 explain() uses the default verbosity mode of the explain command, allPlansExecution. To use a different verbosity use command() to run the explain command directly.
My aggregate query looks something like this
collection.aggregate(pipeline=QUERY, explain=True)
This returns queryPlanner
verbose and not executionStats
.
What mongo shell supports?
db.Item_Process_For_Report.explain("executionStats").aggregate([])
What am I trying to do?
db.command('explain', <What goes here>)
回答1:
As on 22-May-2019 with MongoDB 4.0
pymongo currently allows explain only via db.command() and this internally uses the Aggregation Command and Aggregation which limits explain to a Boolean switch which defaults to QueryPlanner as seen here
来源:https://stackoverflow.com/questions/56255968/how-to-get-python-mongo-aggregate-explain-using-db-command