I want to make a find query on my database for documents that have an input value between or equal to these 2 fields, LOC_CEP_INI
and LOC_CEP_FIM
db.zipcodes.find( {
"LOC_CEP_INI": { "$lte": 69900002 }, "LOC_CEP_FIM": { "$gte": 69900002 } })
You have to invert your field names and query value.
db.zipcodes.find({
LOC_CEP_INI: {$gte: 69923997},
LOC_CEP_FIM: {$lte: 69923997}
});
For your query example to work, you would need your documents to hold an array
property, and that each item in this prop hold a 69923997
prop. Mongo would then check that this 69923997
prop has a value that is both between "LOC_CEP_INI"
and "LOC_CEP_FIM"
for each item in your array
prop.
Also I'm not sure whether you want LOC_CEP_INI <= 69923997 <= LOC_CEP_FIM
or the contrary, so you might need to switch the $gte
and $lte
conditions.
db.collection.find( { field: { $gt: value1, $lt: value2 } } );
https://docs.mongodb.com/v3.2/reference/method/db.collection.find/ refer this mongo provide range facility with $gt and $lt .