The context is group discounts where a group of people between 4-7 would get a 5% discount and a group between 8-12 would get 10%. When I query with 5
people. I get []
back using the following query:
await Discount.find({ amount: { $gte:5, $lte: 8 } })
.then((discounts) => {
console.log(discounts);
})
.catch(next);
But I was trying to get the following object:
[
{
name: '4+ Group Size',
amount: 4,
},
{
name: '8 Group Size',
amount: 8,
}
]
How do I query BETWEEN two values?
2
Answers
For a db like this:
You can use a query:
To get the relevant discount per amount of people in the group
See how the logic works on the playground example using aggregation pipeline only because of the playground limitations.
You can also use the $and operator