Reputation: 2496
I want to find all the documents in mongodb which have a "emotion1" key in "emotions" key. My database structure is like this
{
"word" : "word1",
"emotions" :
{
"emotion1" : "0.25",
"emotion2" : "0.25",
"emotion3" : "0.35"
}
}
I have tried,
db.collection.find({"emotions":{"emotion1":{"$exists":True}}})
db.collection.find({"emotions":{"emotion1":{"$exists":True}}})
However this works for "emotions", key like this,
db.collection.find({"emotions": {"$exists": True}})
Upvotes: 0
Views: 44
Reputation: 61273
You need to use the dot notation.
db.collection.find( { "emotions.emotion1": { "$exists":True } } )
Upvotes: 1