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

2024-09-29 23:32:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在mongodb中找到所有在“emotations”键中有“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}}})

但这对“情绪”有效,关键是

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

Tags: 文档数据库truedbmongodbexistsfind结构

热门问题