MongoDB Query Condition setting

Source: Internet
Author: User
Tags mongodb query


Query criteria
Query query = new query ();
Query criteria
criteria = new criteria ();
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");

if (Stringutils.isnotempty (type) &&!type.equals ("-1")) {
Criteria.and ("type"). is (type);
}

String Contacter=entrustinfovo.getcontacter ();
if (Stringutils.isnotempty (contacter)) {
Criteria.and ("Jsonobj.contacter"). is (contacter);
}

String Provinceid=entrustinfovo.getprovinceid ();
String Provincename=entrustinfovo.getprovincename ();
list<criteria> list = new arraylist<criteria> ();
if (Stringutils.isnotempty (Provinceid) | | Stringutils.isnotempty (Provincename)) {
Criteria.and ("Signuprecordhandlevo.provinceid"). is (Provinceid);
List.add (Criteria.where ("Signuprecordhandlevo.provincename"). is (Provincename));
}
Sale of the consignment and rental of the data is not displayed (1: Sale of housing Commission 2: rental Commission)
List.add (Criteria.where ("type"). In ("3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"));
Processing status
String Handleflag=entrustinfovo.gethandleflag ();
if (Stringutils.isnotempty (Handleflag)) {
Criteria.and ("Signuprecordhandlevo.handleflag"). Is (Integer.parseint (Handleflag));
}

if (list.size () > 0) {
Criterial.oroperator (List.toarray (New Criteria[list.size ()));
Criteria.andoperator (criterial);
}
Query.addcriteria (criteria);
Total number of bars
Long Count = Mongotemplate.count (query, Entrustjsonobj.class, tableconstants.steward_entrust_info);
System.out.print (Query.tostring ());
Page out
Query.skip ((pageNo-1) * pageSize);//Skip is the equivalent of which record starts
Query.limit (pageSize);//How many records are taken from the start of skip

Sort
Sort sort = new sort (Sort.Direction.DESC, "createtime");
Query.with (sort);

Pagebean.settotalcount (count);

MongoDB Query Condition setting

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.