检查 mongo 中是否存在字段中的数组键


Check if an array key in a field exists in mongo

{
 "_id": ObjectId("502626aad4ebdf600b000000"),
 "created_at": ISODate("2012-08-11T09: 32: 26.0Z"),
 "excerpt": "lotto results for August 11, 2012",
 "results": {
    "1-digit" : {
        "0" : "1",
    },
    "2-digit" : {
        "0" : "1",
        "1" : "2",
    },
    "3-digit" : {
        "0" : "1",
        "1" : "2",
        "2" : "3",
    }
    }
}

我应该如何检查results.1-digit是否存在?

您可以运行查询{results.1-digit : {$exists : true }}

希望对您有所帮助。

我相信在外壳中添加引号同样重要

{"results.1-digit" : {$exists : true }}