I would like to find name with alexa in nested object Playground: https://mongoplayground.net/p/rqYQtf0liaX
[
{
item: "journal",
instock: [
{
warehouse: "A",
qty: 5,
items: null
},
{
warehouse: "C",
qty: 15,
items: [
{
name: "alexa",
age: 26
},
{
name: "Shawn",
age: 26
}
]
}
]
}
]
What i have tried so far and this returns no document found
db.collection.find({
"instock.items": {
$elemMatch: {
name: "Alexa"
}
}
})
Mongo is case sensitive.
play
db.collection.find({
"instock.items": {
$elemMatch: {
name: "alexa"
}
}
})
If you want to have case-insensitive, use regex or $text. With $regex, you can use $elemMatch.
db.collection.find({
"instock.items": {
$elemMatch: {
name: {
$regex: "alexa",
$options: "i"
}
}
}
})
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