Reputation: 2692
I'm trying to pick documents with cost fields between 0 and 5 then trying to pick documents with cost ranges between 10 and 15. For this, I'm using MongoDB aggregation
const something = await dummyModel.aggregate([
{
$match: {
fieldA: {
$in: arryOfIds,
},
cost: {
$or: [
{ $gte: 0, $lt: 5 },
{ $gte: 10, $lt: 15 },
],
},
},
},
]);
With the above approach, I'm getting this error from mongoose.
"message": "unknown operator: $or",
Any Idea on this to pick ranges in MongoDB
using mongoose
Upvotes: 1
Views: 880
Reputation: 20334
You should do it with find
query.
db.collection.find({
"fieldA": {
"$in": arryOfIds,
},
"$or": [
{
"cost": {
"$gte": 0,
"$lt": 5
}
},
{
"cost": {
"$gte": 10,
"$lt": 15
}
}
]
})
Upvotes: 1