Cursor.explain() extremely slow (PyMongo 3.10.1; MongoDB 4.4)

Hi all,

the following query issued via mongo shell returns the result instantly:

db.coll.find({}, { A:true, B:true, C:true}).hint('A_1_C_1_B_1').explain()

whereas the same query issued via PyMongo returns result in almost 10 minutes. I tried both forms of supplying the hint, no difference:

coll.find({}, { A: True, B: True, C: True}).hint('A_1_C_1_B_1').explain()  # form 1
coll.find({}, { A: True, B: True, C: True}, hint='A_1_C_1_B_1').explain() # form 2

any ideas why is that and how to fix this issue?

PyMongo 3.10.1
MongoDB 4.4

Cursor.explain() uses the default explain verbosity (“allPlansExecution”). See the note in: https://pymongo.readthedocs.io/en/stable/api/pymongo/cursor.html?highlight=explain#pymongo.cursor.Cursor.explain

Note: 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.

For some more context see this related ticket: https://jira.mongodb.org/browse/PYTHON-1656

2 Likes