Java to MongoDB and, in, or frequently use operations

Source: Internet
Author: User

Dbcollection Dbcon = null;

DBObject query = new basicdbobject ();

Basicdblist values = new basicdblist ();

//or How to use --->> Check Salary salary<3000 or salary>10000

Values.add (new basicdbobject ("Salary", new basicdbobject ("$GT", 10000));

Values.add (new basicdbobject ("Salary", new basicdbobject ("$lt", 3000));

Query.put ("$or", values);

Dbcursor dbcursor = Dbcon. Find (query);

//end///

// Enquiry salary>1000 or age<22

Values.add (new basicdbobject ("Salary", new basicdbobject ("$GT", 10000));

Values.add (new Basicdbobject ("Age", new basicdbobject ("$lte", 22));

Query.put ("$or", values);

Dbcursor DbCursor2 = dbcon.find (query);

//end///

// in How to use --->> Enquiry salary in [+]

Values.add (3000);

Values.add (10000);

Query.put ("salary", new basicdbobject ("$in", values));

Dbcursor DbCursor3 = dbcon.find (query);

//and How to use --->> salary>10000 and age<22

Query.put ("salary", new basicdbobject ("$GT", 10000));

Query.put ("Age", new basicdbobject ("$lt", 22));

       dbcursor  dbCursor4  = dbcon.find (query);

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.