$ and查询不返回结果 [英] $and query returns no result

查看:61
本文介绍了$ 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.

这篇关于$ and查询不返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆