Is it possible with mango query to find those documents, which have a provided string in an array field?
Say,
const doc = {
_id: 'testdoc',
tags: ['pouch', 'couch', 'mysql'],
}
$db.find({ selector: {
tags: {
$has: 'pouch' // what goes here?
}
}})
You have to use the $elemMatch operator
{
selector: {
tags: {
"$elemMatch": { $eq: "pouch" }
}
}
}
For further documentation, head here
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