Tomas
Tomas

Reputation: 81

Mongo query data that not in range - not between

I try to query some data that is not between integer range, I have some problems with that.

For now i managed to query "between" range:

{ '$where': "#{some_method(field)} <= #{value[1]} && #{some_method(field)} >= #{value[0]}" }

I need to search for data that is not in the range provided. How can I do that?

Upvotes: 0

Views: 1282

Answers (1)

Amolpskamble
Amolpskamble

Reputation: 978

You can write a query using $or operator to get documents, not in a specific range.

Eg. The following query will give you documents which values are not between 50 to 100.

db.getCollection('collection_name').find({$or:[{"some_field":{$lte:50}},{"some_field":{$gte:100}}]})

Upvotes: 2

Related Questions