Below query i have written to get range between 400 to 800
db.products.find({$and: [{price: {$gt: 400}}, {price: {$lt: 800}}]});
But how to get values that are not between range of 400 to 800
db.products.find({$and: [{price: {$lt: 400}}, {price: {$gt: 800}}]});
why above query not shown any result?
Thanks
>Solution :
Simple $or will do the job:
(price cannot be <400 & >800 at the same time)
db.collection.find({
$or: [
{
"price": {
$lt: 400
}
},
{
"price": {
$gt: 800
}
}
]
})