MongoDB。 db.collection.explain().find() 与 db.collection.find().explain()

MongoDB. db.collection.explain().find() vs db.collection.find().explain()

这两个命令有什么区别?

db.collection.explain().find() 
db.collection.find().explain()

运行 db.collection.explain() returns 一个对象,可用于生成聚合、计数、查找、分组、删除和更新操作的解释计划。从 MongoDB 3.0 开始,这是生成解释计划的首选方式。

cursor.explain(允许 db.collection.find().explain() 运行)主要是为了向后兼容 3.0 之前的 MongoDB 版本。这将生成与 db.collection.explain() 相同的解释输出,但仅限于查找操作。

如果其他都一样,我建议使用 db.collection.explain(),它支持更多的操作。