MongoDB "Conditional Query"-Criteria for comparison

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.