Explain function exception with findOne

Hi All,

I was learning index and thought of checking how plan work with findOne. When I executed below query


the below exception is raised:

uncaught exception: TypeError: db.people.findOne(…).explain is not a function

Any thoughts?


Hello @Yadvinder_Kumar, welcome to the forum.

The explain method cannot be used with the findOne method. Here are the list of methods on which the explain can be used with: db.collection.explain

Explain can be used two ways, with the find method:

  • db.collection.explain().find()
  • db.collection.find().explain(): The find method returns a cursor. You can apply the explain on the cursor.

Thank you @Prasad_Saya.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.