The "MongoDB"-java implements the and, or, in operation of MongoDB

Source: Internet
Author: User

1) and (with and when multiple conditions are met)

publicvoidtestAnd(){          new BasicDBObject();        //agender=‘female‘ AND age > 27        queryCondition.put("agender""female");        queryCondition.put("age"new BasicDBObject("$gt"27));        DBCursor dbCursor = coll.find(queryCondition);       }    

2) Or (two conditions satisfy one of them)

 Public void Testorsinglefield() {DBObject querycondition =NewBasicdbobject ();//age<15 OR age>27Basicdblist values =NewBasicdblist (); Values.add (NewBasicdbobject ("Age",NewBasicdbobject ("$GT", -))); Values.add (NewBasicdbobject ("Age",NewBasicdbobject ("$lt", the))); Querycondition.put ("$or", values);       Dbcursor dbcursor = Coll.find (querycondition); }

3) in (requires the value of a field in a range)

publicvoidtestIn(){        new BasicDBObject();              //age in [13, 47]        new BasicDBList();        values.add(13);        values.add(47);        queryCondition.put("age"new BasicDBObject("$in", values));        DBCursor dbCursor = coll.find(queryCondition);       }    

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The "MongoDB"-java implements the and, or, in operation of MongoDB

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.