Filtering of collections with multiple OR options

Hi,

I am creating what I think to be a complex search / filtering option for a collection and need some assistance. Looking to create a filter that allows an “OR” function on a specific field.

Trying to have something like the following return results when the “make” field equals any of these options, however as soon as I specify 1 value for “make” I get a blank collection.

VehiclesJson.find({“make”:[“KIA”,“Chrysler”,“Nissan”]},{sort: sortBy});

Currently not working filters:

{“newUsed”:“2”,“make”:[“KIA”,“Chrysler”],“year”:{"$gte":2000,"$lte":2016},“mileage”:{"$gte":0,"$lte":200000},“price”:{"$gte":0,"$lte":50000}}

{“newUsed”:“1”,“make”:[“KIA”],“year”:{"$gte":2000,"$lte":2016},“mileage”:{"$gte":0,"$lte":200000},“price”:{"$gte":0,"$lte":50000}}

answer is $in, check in mongodb docs

https://docs.mongodb.org/v3.0/reference/operator/query/or/

Thank you. Looks like that will work.

1 Like