3

What is the difference between this two commands?

db.collection.explain().find() 
db.collection.find().explain()
Sergey P.
  • 194
  • 1
  • 12

1 Answers1

2

Running db.collection.explain() returns an object that can be used to generate explain plans for aggregate, count, find, group, remove and update operations. As of MongoDB 3.0 this is the preferred way to generate an explain plan.

cursor.explain (which allows for a db.collection.find().explain() run) is provided mainly for backwards compatibility with pre-3.0 MongoDB releases. This will generate the same explain output as db.collection.explain() but is limited to the find operation.

If all else is the same, I would recommend using db.collection.explain() which supports a greater set of operations.

James Wahlin
  • 2,811
  • 21
  • 22