Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

Example: user input a number to the system with value : 69923994, then I use this input to search my database for all documents that have this value between the range of the fields LOC_CEP_INI and LOC_CEP_FIM.

One of my documents (in this example this document is selected by the query because the input is inside the range):

 {
   "_id" : ObjectId("570d57de457405a61b183ac6"),
   "LOC_CEP_FIM" : 69923999, //this field is number
   "LOC_CEP_INI" : 69900001, // this field is number
   "LOC_NO" : "RIO BRANCO",
   "LOC_NU" : "00000016",
   "MUN_NU" : "1200401",
   "UFE_SG" : "AC",
   "create_date" : ISODate("2016-04-12T20:17:34.397Z"),
   "__v" : 0
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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 .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...