I'm working on a query where i'm using $and to use multiple filters or conditions. when i explain the query so i found that $and is not working like javaScript && operator. How can i achieve JavaScript && like functionality in mongoDB query?
MyModel.aggregate([{
$match: {
$and: [{
$text: {
$search: mappedSearchTxt
}
}, ...regexFilter, ...filters]
}
}])
Example document
{
_id: '1234'
name: 'John',
age: 34,
father: 'Andy'
}
Your $and query should look like - $and: [{ .... }]
.find({ $and: [{ name: 'John'}, { father: 'Andy' }])
The above is just a demostration of $and, because the following query works the same.
.find({ name: 'John', father: 'Andy' })