这两个命令有什么区别?

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

最佳答案

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

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

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

关于MongoDB。 db.collection.explain().find() 与 db.collection.find().explain(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32249655/

10-12 05:14