为什么MongoDB在使用simple find()查询进行过滤和排序之前进行投影?
嗯。我觉得很奇怪。。。但事情是这样的 例如,我们有一个集合,其中包含文档的为什么MongoDB在使用simple find()查询进行过滤和排序之前进行投影?,mongodb,projection,sql-execution-plan,Mongodb,Projection,Sql Execution Plan,嗯。我觉得很奇怪。。。但事情是这样的 例如,我们有一个集合,其中包含文档的ageFrom、ageTo、price和属性。其中4个有索引(在我的例子中,它有更多的属性) 所以。。。如果我跑 db.getCollection('product') .find({ "age_from": {"$gte": 36}, "age_to": {"$lte": 36} }, {"enabled":1}) // <-- here's the trick! .sort({ "pric
ageFrom
、ageTo
、price
和属性。其中4个有索引(在我的例子中,它有更多的属性)
所以。。。如果我跑
db.getCollection('product')
.find({
"age_from": {"$gte": 36},
"age_to": {"$lte": 36}
}, {"enabled":1}) // <-- here's the trick!
.sort({
"price": 1
}).explain().queryPlanner.winningPlan
db.getCollection(“产品”)
.找到({
“年龄从”:{“$gte”:36},
“年龄到”:{“$lte”:36}
},{“enabled”:1})//但是如果你指定{“enabled”:1}
,如果你省略它,它就不会首先投影,不是吗?是的。它既不会首先投射,也不会投射到其他任何地方。