db.test.insert({_id:1,communications:[{type:’sms’}]})
db.test.find()
{ "_id" : 1, "communications" : [ { "type" : "sms" } ] }
Ok, its inserted
db.test.find({‘communications’:{type:’sms’}})
{ "_id" : 1, "communications" : [ { "type" : "sms" } ] }
Ok, I can find it if its an exact match
db.test.update({_id:1}, {communications:[{type:’sms’,call_id:9878}]}
Now I updated it such that the hash nested in the array has two keys
.test.update({_id:1}, {communications:[{type:’sms’,call_id:9878}]})
But I can’t find it bc the hash is not the exact match! NOOOOO!
db.test.find({‘communications’:{type:’sms’}}).count()
=>0
So, how can I do a search like that where I want to match on one of the keys in a hash in an array?
If I’ve understood correctly (no guarantees I have!), then I think what you are looking for is the dot notation.
Here’s the reference on MongoDb.org with all the examples.