Ahmed Mohamed Talaat
Ahmed Mohamed Talaat

Reputation: 39

Get Value between to columns in Mongo

make:"AC"
model:"ACE"
generation:"1 generation"
year_begin:1993
year_end:2000
serie:"Cabriolet"

I want to wite a mongodb query to get cars if the model year between year_begin and year_end I tried to write it but not work this is my query :

> {'year_begin':{'$gte':1994},'year_end':{'$lte':1994}}

Upvotes: 2

Views: 77

Answers (1)

Praveen Rewar
Praveen Rewar

Reputation: 961

Try using $and and query should look like below:

db.collection.find({$and:[{year_begin:{$lte: 1994 }}, {year_end:{$gte:1994}}]} )

Upvotes: 2

Related Questions