Reputation: 78
I am having a field as build and another as data in my MongoDB. my build field is as b3312, b3313, b3313... I want to fetch data for a range of builds. can we add regex with it and gt in find query? or is there any other solution to this issue?
Upvotes: 0
Views: 179
Reputation: 143
Try this one:
let build_ids = ["b3312","b3313","b3314"];
db.collectionName.find({build: {$in: build_ids}})
Upvotes: 0
Reputation: 5051
you can use
$lte
selects the documents where the value of the field is less than or equal to (i.e. <=) the specified value.
$gte
selects the documents where the value of the field is greater than or equal to (i.e. >=) a specified value
db.collectionName.find( { build : { $gte: "b3312", $lte : "b3314"} } )
result:
/* 1 */
{
"_id" : ObjectId("60118271fec3d8db92a39872"),
"build" : "b3312"
}
/* 2 */
{
"_id" : ObjectId("60118279fec3d8db92a3987e"),
"build" : "b3313"
}
/* 3 */
{
"_id" : ObjectId("6011827ffec3d8db92a3988b"),
"build" : "b3314"
}
Upvotes: 1