MongoDB通过指定嵌套值来查找对象

时间:2016-10-13 12:40:14

标签: mongodb meteor

[
{
    customer: {
        field 1: {},
        field 2: {},
        answers: {
            "BUSI_EXP": { "answered": true, "updated": "date" },
            "NEW_HOME": { "answered": true, "updated": "date" },
            "VEHICLE": { "answered": true, "updated": "date" }
        }
    }
},
{
    customer: {
        field 1: {},
        field 2: {},
        answers: {
            "BUSI_EXP": { "answered": false, "updated": "date" },
            "NEW_HOME": { "answered": false, "updated": "date" },
            "VEHICLE": { "answered": true, "updated": "date" }
        }
    }
}
]

这是我的客户系列。如您所见,它有一个答案字段,每个键都有一个回答标记。我如何让所有回答任何答案的客户都是真的?

1 个答案:

答案 0 :(得分:2)

尝试:

    db.collectionname.find({ $or:[{"customer.answers.BUSI_EXP.answered": true},
{"customer.answers.NEW_HOME.answered": true},
{"customer.answers.VEHICLE.answered": true}});