• java中Mongo


    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() + "'."); } }
  • 相关阅读:
    Ubuntu下Geary安装
    (1)html初步--表格的使用
    MYSQL笔记
    三,springboot集成mybatis
    一台服务部署多个tomcat注意事项
    Apache和Tomcat整合(一个Apache 不同域名处理多个不同业务)
    linux 安装 apache
    linux笔记
    关联查询一张小表。对性能有影响吗(mysql)
    关于mysql的临时表并行的问题
  • 原文地址:https://www.cnblogs.com/an5211/p/7600462.html
Copyright © 2020-2023  润新知