If I have a document format in my coms collection:
{
"recipients": {
"key1": "value1",
"key2": "value2",
"key3": "value3",
}
}
I want to get all documents which have the exact same keys. In other words, in the above example, if I query for "key1", "key2", "key3", I get the above document. If, on the other hand, I have the following document:
{
"recipients": {
"key1": "value1",
"key2": "value2",
"key3": "value3",
"key4": "value4",
}
}
Querying for "key1", "key2", "key3" should return nothing.
A quick solution with $exists:
db.collection.find({
"recipients.key1":{
$exists:true
},
"recipients.key2":{
$exists:true
},
"recipients.key3":{
$exists:true
},
"recipients.key4":{
$exists:false
}
})
But this require to know all other possible keys and can be quite painfull to write..