Reputation: 3437
I have records which contain 3 columns
Title
MinValue
MaxValue
.
Now i am work on filter and wan to get the title of the my inputted value.
Records :
[
{
title : "1-10",
minValue : 1,
maxValue : 10
},
{
title : "11-20",
minValue : 11,
maxValue : 20
},
{
title : "21-30",
minValue : 21,
maxValue : 30
}
]
I need mondodb query which will return the record
consider I input 5 then it will return first record
Upvotes: 0
Views: 12
Reputation: 7588
Here's a solution:
var target = 5;
db.foo.find({minValue: {"$lt":target}, maxValue: {"$gt":target}}, {_id:0,title:1});
The second arg to find
is the projection. It says do NOT show _id but do show title.
Upvotes: 1
Reputation: 6734
You can use $gt and $lt parameters.
.find({ minValue : { $gt : 5}, maxValue : { $lt : 5 }})
Upvotes: 1