I have a document like this:
{
"_id":ObjectId("5b306824a1eab22e77858c88"),
"data":{
"Key":[
[
"1529587723",
"KeyIn"
],
[
"1529587723",
"Num"
],
[
"1529667745",
"KeyIn"
]
]
},
"devicecode":"MP1D1XAH@LENOVO"
}
my question is how to find all records with "KeyIn"? I tried
db.dataup.find({ "data.key": "KeyIn" })
but it doesn't work.
You need to use double nested $elemMatch to find in double nested arrays
db.collection.find({
"data.Key": {
"$elemMatch": {
"$elemMatch": { "$in": ["KeyIn"] }
}
}
})
MongoPlayground
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