Spring DATA MongoDB @DBref query, OR and and Union queries

Source: Internet
Author: User

@DBref The document association, when queried by that type, add the field name of the associated table to the field name, as follows:

Criteria.where ("BlogGroup. $id"),

$id represents the OID field of the associated table.

OR and and union queries

such as the query (a = 1 and b = 2) or (A = 3 and b =4), or the number of uncertainties,

Then a criteria array is defined, the condition group is entered into the array, and the array is assigned to the Orcriteria method.

@Override
Public list<blog> Find (list<groupattention> groupattentions) {
Query query = new query ();
criteria = new criteria ();
criteria[] CriteriaList = new criteria[groupattentions.size ()];
for (int i=0;i<groupattentions.size (); i++) {
Criteria Criteriaand = new criteria ();
Criteriaand.andoperator (Criteria.where ("BlogGroup. $id"). Is (new ObjectId (Groupattentions.get (i). Getgroupid ())). and ("Bloglevel"). GTE (Groupattentions.get (i). Getgrouplevel ()));
Criterialist[i] = Criteriaand;
}
Criteria.oroperator (criterialist);
Query.addcriteria (criteria);
return mongotemplatedatabase.find (query, Blog.class);
}

Spring DATA MongoDB @DBref query, OR and and Union queries

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.