Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么MongoDB在使用simple find()查询进行过滤和排序之前进行投影?_Mongodb_Projection_Sql Execution Plan - Fatal编程技术网

为什么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}
,如果你省略它,它就不会首先投影,不是吗?是的。它既不会首先投射,也不会投射到其他任何地方。