$ and查询不返回结果

$ and查询不返回结果

问题描述:

好吧,这杀了我.也许已经晚了,我忘记了一些东西,但这应该可行.

Ok this one is killing me. Maybe its late and I am forgetting something, but this should work.

出于测试目的,我的收藏中大约有6000个文档.有一个名为Priority的属性,每个实例的值均为2.

For test purposes, I have about 6000 documents in my collection. There is a property called Priority which has a value of 2 in every instance.

以下两个查询均返回全部 6000个文档:

The following two queries each return all 6000 documents:

{
    Priority: {
        $gt: 1
    }
}

{
    Priority: {
        $lt: 10
    }
}

但是,此查询返回0个结果,并且根据说明,对所有6000个文档进行了全面扫描:

This query, however, returns 0 results and according to the Explain, does a full scan of all 6000 documents:

{
$and: [
        {
            Priority: {
                $gt: 1
            }
        },
        {
            Priority: {
                $lt: 10
            }
        }
    ]
}

我错过了什么吗?

如果我说:我需要一个可以坐四个人的汽车和一个至少可以坐八个人的汽车的人",那个需要一辆汽车的人坐了八个人通常不被认为有资格.您的查询只能由具有两个优先级值,小于10且大于1的条目来满足.

If I said, "I need someone with a car that can seat four people and a car that can seat at least eight people", someone with a single car that sat eight people would not ordinarily be understood to qualify. Your and query can only be satisfied by an entry with two values for Priority, one less than 10 and one greater than 1.

文档链接到mongoDB的多键语义.

The docs for and have a link to the multikey semantics of mongoDB.