I have documents stored in mongo database following this schema:
{
map:{
key1:value,
banana:value2
....
}
}
How can I query objects based on keys in this map ?
e.g I want to get all the documents which map contains key that equals banana
.
Maps are accessed the same way as normal nested values.
This means that you can use the $exists
operator to check if the key exists.
db.collection.find( { "map.banana" : { $exists : true } } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With