Read the premise: the background of the code is this ID other posts: IP library Query
The format is as follows:
Begin End Provinces
18533376,18534399, Inner Mongolia Autonomous Region, Holonbuyr
Simple code:
public static iplocation getlocation ( Long iplong) {iplocation iplocation = new iplocation ();// Gets the handle to the table dbcollection collection = null;// encapsulates the query condition basicdbobject basicdbobject = null;try {collection = db.getcollection (constant.ipbase); basicDBObject = new basicdbobject ();// begin <= iplong <= endbasicdbobject.put ("Begin", New basicdbobject ("$lte", iplong)), Basicdbobject.put ("End", new basicdbobject ("$gte", iplong)); List<dbobject> dbobjectlist = collection.find (Basicdbobject). ToArray (); Iplocation.setprovince (Dbobjectlist.get (0). Get ("province"). ToString ()); Iplocation.setcity (Dbobjectlist.get (0). Get ("City"). ToString ());} catch (exception e) {p ("There was an error in the process of checking the Mixboxipbase Library");} return iplocation;}
Over here
Basicdbobject.put ("Begin", New Basicdbobject ("$lte", Iplong)); LTE: Less than equals means begin = Iplongbasicdbobject.put ("End", New Basicdbobject ("$gte", Iplong)); Get: is greater than or equal to the end "= Iplong combined to look at the begin < Iplong < end, please do not make any mistake in detail.
MongoDB "Conditional Query"-Criteria for comparison