如何确定一个字段是否存在于一个键的值中?

how to determine whether a field exists inside a value of a key?

我想在 mongodb 中找到所有在 "emotions" 键中有 "emotion1" 键的文档。 我的数据库结构是这样的

{
    "word" : "word1",
    "emotions" : 
     {
        "emotion1" : "0.25",
        "emotion2" : "0.25",
        "emotion3" : "0.35"
     }
}

我试过了,

db.collection.find({"emotions":{"emotion1":{"$exists":True}}})
db.collection.find({"emotions":{"emotion1":{"$exists":True}}})

但是这适用于 "emotions",像这样的键,

db.collection.find({"emotions": {"$exists": True}})

您需要使用dot notation

db.collection.find( { "emotions.emotion1": { "$exists":True } } )