在mongodb集合中查找键与文档列表中的特定值匹配的文档

问题描述 投票:0回答:1

我是MongoDB的新手,我正在尝试查询以下集合(名为sample):

{
    "_id": "thresholds",
    "thresholds": [{
        "GRADE": "CC004",
        "C": "",
        "CF": "",
        "MN": "0.01",
        "N": "",
        "P": "0.03",
        "SI": "",
        "CR": ""
    }, {
        "GRADE": "CC005",
        "C": "",
        "CF": "",
        "MN": "",
        "N": "",
        "P": "",
        "SI": "",
        "CR": ""
    }]
}

我正在尝试检索“ GRADE”为“ CC004”的整个记录​​。

现在,我正在执行以下操作:db.sample.find({"thresholds": {"GRADE": "CC004"}})。但是,它返回空值,因为未找到任何内容。如何重新查询以查找感兴趣的条目?

python python-3.x mongodb pymongo pymongo-3.x
1个回答
0
投票

Podrias hacer la siguiente consulta:

db.sample.find({"thresholds.GRADE": "CC004"})
© www.soinside.com 2019 - 2024. All rights reserved.