码迷,mamicode.com
首页 > 编程语言 > 详细

java中Mongo

时间:2017-09-27 11:30:43      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:his   lan   value   lang   ons   cond   ati   重复   jin   

1.  query.fields().include("idfa").include("imei").include("id").include("os");  返回数据中包含这几个字段

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])));


toArray解释

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;   

    }  

  由①得出如下查询语句

{ "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“));
从下面源码可以看出上面中的key不能是重复的值


public
Query 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 new InvalidMongoDbApiUsageException("Due to limitations of the com.mongodb.BasicDBObject, you can‘t add a second ‘" + key + "‘ criteria. " + "Query already contains ‘" + existing.getCriteriaObject() + "‘."); } }

 

java中Mongo

标签:his   lan   value   lang   ons   cond   ati   重复   jin   

原文地址:http://www.cnblogs.com/an5211/p/7600462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!