MONGO in Java

Source: Internet
Author: User

1. Query.fields (). Include ("IDFA"). Include ("IMEI"). Include ("id"). include ("OS"). These fields are included in the return data

2.


list<criteria> criterias = new arraylist<> ();
Criterias.add (Criteria.where ("Time"). GT ("2017-09-20 10:02:26"));
Criterias.add (Criteria.where ("time"). Lt ("2017-09-27 10:02:26"));
Criterias.add (Criteria.where ("IMEI"). Is ("9686854123"));
Query.addcriteria (New Criteria () Andoperator (Criterias.toarray (new criteria[0]));

Ii
ToArray explanation

Public <T> t[] ToArray (t[] a) {

if (a.length < size)

a = (t[]) Java.lang.reflect.Array.

Newinstance (A.getclass (). Getcomponenttype (), size);

system.arraycopy (elementdata, 0, a, 0, size);

if (a.length > Size)

A[size] = null;

return A;

}

The following query statement is obtained by ①

{"Channel":"Jinritoutiao","$and": [ {"IMEI":"96868541236"}, {" Time": {"$lt":"2017-09-27 10:02:26"}}, {" Time": {"$GT":"2017-09-20 10:02:26"}}]
}

3.


Query.addcriteria (Criteria.where ("Key"). Is ("Value"));
from the source below can be seen above the key cannot be a duplicate value


PublicQuery Addcriteria (criteriadefinition criteriadefinition) {criteriadefinition existing= (criteriadefinition) This. Criteria.Get(Criteriadefinition.getkey ()); String Key=Criteriadefinition.getkey (); if(Existing = =NULL) { This. Criteria.put (key, criteriadefinition); return This; } Else { Throw NewInvalidmongodbapiusageexception ("Due to limitations of the com.mongodb.BasicDBObject, you can ' t add a second '"+ key +"' criteria."+"Query already contains '"+ existing.getcriteriaobject () +"'."); } }

MONGO in Java

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.