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() + "'.");
}
}
java中Mongo的更多相关文章
- java中mongo的条件查询
@Override public Page<ProductInfo> findAll(Pageable pageable, ProductInfo productInfo) { //创建一 ...
- Java中使用MongoDB
一.为MongoDB设置用户名和密码 MongoDB中验证用户和密码的条件: 1. 服务器启动的时候打开授权认证,即修改MongoDB的配置文件mongodb.conf,增auth = true # ...
- java操作mongo
语法正确时,字段不匹配时,Mongo并不会抛出异常,这在语句调试时需多加注意. mongo自身的时间存储格式与java中的并不是完全匹配,Mongo采用UTC格式,而java中一般为GMT格式,有个时 ...
- java中的锁
java中有哪些锁 这个问题在我看了一遍<java并发编程>后尽然无法回答,说明自己对于锁的概念了解的不够.于是再次翻看了一下书里的内容,突然有点打开脑门的感觉.看来确实是要学习的最好方式 ...
- java中的字符串相关知识整理
字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- java中Action层、Service层和Dao层的功能区分
Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO只 ...
- Java中常用集合操作
一.Map 名值对存储的. 常用派生类HashMap类 添加: put(key,value)往集合里添加数据 删除: clear()删除所有 remove(key)清除单个,根据k来找 获取: siz ...
- java中的移位运算符:<<,>>,>>>总结
java中有三种移位运算符 << : 左移运算符,num << 1,相当于num乘以2 >> : 右移运算符,num >& ...
随机推荐
- 014PHP基础知识——流程控制(二)
<?php /** *switch 分支语句: * switch(表达式){ * case 值1: * ... * break; * * case 值2: * ... * break; * de ...
- windows 下git 的配置安装与使用
一.安装GIT(过于简单略过) 二.配置git 二(一).配置git的user name和email 打开 git bash,输入 $ git config --global user.name &q ...
- New Concept English three(13)
1原文打字 32w/m 错词27个 After her husband had gone to work, Mrs Richards sent her children to school and w ...
- c# DataTable 数据集处理DataTableHandler
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- asp.net string有多行文字
用如下格式设置
- ubuntu16 tomcat7安装和编码修改
有直接通过命令安装的,但是我还是喜欢把文件下载下来,然后自己配置. 1,下载tomcat7二进制文件 https://tomcat.apache.org/download-70.cgi 2,解压tom ...
- [置顶]
flume高并发优化——(15)中间件版本升级
在系统平稳运行一年的基础上,为提供更好的服务,现针对java,kafka,flume,zk,统一进行版本升级,请各位小伙伴跟着走起来,不要掉队啊! 名称 老版本号 新版本号 jdk 1.7.0_25 ...
- Linux 释放物理内存和虚拟内存
1.查看内存占用情况 $ free -m -h total used free shared buff/cache available Mem: .7G .0G .9G 385M 780M .0G S ...
- python最重要的模块logging
logging模块 这个模块是目前最重要的模块!!!我一定给讲透彻一点 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python中的loggi ...
- 使用TR1的智能指针
作为C++程序员,在没有智能指针,手动管理内存的蛮荒岁月里,可以说是暗无天日,痛苦异常.直到上帝说,还是要有光,于是智能指针进了标准.C++码农的日子总算好起来了. 虽然一直鄙视着没有显式指针的语言, ...