-2

Hi i'm trying to translate this javascript expression with mongo:

db.zipcodes.find( { $where: "69900002 >= obj.LOC_CEP_INI && 69900002 <= obj.LOC_CEP_FIM" } );

To a mongo query. I need that because the javascript is not performatic for query big data.

What i need is search objects where the field LOC_CEP_INI is bigger or equal to 69900002 and LOC_CEP_FIM is equal or smaller than LOC_CEP_INI Thanks!

OUTPUT Example (69900002 is bigger than LOC_CEP_INI and 69900002 is smaller than 69900002:

 {
"create_date": "2016-04-12T20:17:34.397Z",
 "__v": 0,
"UFE_SG": "AC",
"MUN_NU": "1200401",
"LOC_NU": "00000016",
"LOC_NO": "RIO BRANCO",
"LOC_CEP_INI": 69900001,
"LOC_CEP_FIM": 69923999,
"_id": "570d57de457405a61b183ac6"
}
7
  • What are you trying to do here? Commented Apr 13, 2016 at 14:44
  • @user3100115 i m trying to search objects where the field LOC_CEP_INI is bigger or equal to 69900002 and LOC_CEP_FIM is equal or smaller than LOC_CEP_INI Commented Apr 13, 2016 at 14:47
  • Please post sample document with the expected output. Commented Apr 13, 2016 at 14:50
  • 4
    Isn't this the same as your previous question? Commented Apr 13, 2016 at 15:00
  • 2
    @michelpm1 How is it functionally any different though? The answers are the same for both. Commented Apr 13, 2016 at 15:09

1 Answer 1

2

You need to use the $lte and the $gte query operators to select those document where "LOC_CEP_INI" is lower than 69900002 and "LOC_CEP_FIM" is greater than 69900002.

db.zipcodes.find( {  
    "LOC_CEP_INI": { "$lte": 69900002 }, 
    "LOC_CEP_FIM": { "$gte": 69900002 } 
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.