1、查询所有

@Test
public void query() throws Exception {
final Query<Employee> query = datastore.createQuery(Employee.class);
final List<Employee> list = query.asList();
list.forEach(e -> Console.log("{}", e));
}

输出:

Employee(id=5bcef23890c1d9280c07128e, name=小弟1, manager=null, directReports=[], salary=2000.0)
Employee(id=5bcef23890c1d9280c07128f, name=小弟2, manager=null, directReports=[], salary=3000.0)
Employee(id=5bcef23890c1d9280c071290, name=zuoys, manager=null, directReports=[Employee(id=5bcef23890c1d9280c07128e, name=小弟1, manager=null, directReports=[], salary=2000.0), Employee(id=5bcef23890c1d9280c07128f, name=小弟2, manager=null, directReports=[], salary=3000.0)], salary=10000.0)
Employee(id=5bcef45d90c1d91d509941cd, name=小弟3有父, manager=Employee(id=5bcef23890c1d9280c071290, name=zuoys, manager=null, directReports=[Employee(id=5bcef23890c1d9280c07128e, name=小弟1, manager=null, directReports=[], salary=2000.0), Employee(id=5bcef23890c1d9280c07128f, name=小弟2, manager=null, directReports=[], salary=3000.0)], salary=10000.0), directReports=[], salary=22.0)

使用asList()是可以的,但实际上,fetch()通常是更好的选择。

2、条件过滤

//条件过滤-field
@Test
public void query2() throws Exception {
List<Employee> list = datastore.createQuery(Employee.class)
.field("salary").lessThanOrEq(22)
.asList();
list.forEach(e -> Console.log("{}", e));
}
//条件查询-filter
@Test
public void query3() throws Exception {
List<Employee> list = datastore.createQuery(Employee.class)
.filter("salary <=", 22)
.asList();
list.forEach(e -> Console.log("{}", e));
}

使用filter比fiele更简洁,但要注意语法。

morphia(3)-查询的更多相关文章

  1. mongodb morphia关联查询一例

    //...此处省略了import... /** * Created by shenzhigang on 4/15/16. */ public class Main { public static vo ...

  2. morphia(6-1)-查询

    1.filter morphia语法: query.filter("price >=", 1000); mongodb语法: { price: { $gte: 1000 } ...

  3. morphia 框架 mongodb内嵌查询

    mongodb中存储的文档格式如下,实现查询fromdata下did和dvid为指定值的数据 { "_id": { "$oid": "553f4a9f ...

  4. 使用morphia实现对mongodb的聚合查询

    morphia是谷歌的一个针对mongodb的数据化持久框架: 关于mongodb的介绍不在这里展示,直接进入主题:采用morphia实现对mongodb的聚合查询 这里获取所有学生的分数总和 spr ...

  5. Spring Data MongoDB 五:进阶文档查询(分页、Morphia)(二)

    Spring Data MongoDB 三:基本文档查询(Query.BasicQuery)(一) 学习MongoDB 六: MongoDB查询(游标操作.游标信息)(三) 一.简单介绍 Spring ...

  6. mongodb 对内嵌文档(数组) group分页查询,并设置查询条件

    文档示例Account的其中一条记录: // collection: Account { "_id" : ObjectId("5843e38e535f3708f759b2 ...

  7. MongoDB的ORM框架——Morphia

    1.引入pom <dependency> <groupId>org.mongodb.morphia</groupId> <artifactId>morp ...

  8. Mongodb 的ORM框架 Morphia之注解

    @Entity("bands") public class Band { @Id ObjectId id; String name; String genre; @Referenc ...

  9. mongodb使用实践---mongodb+mongo-java-driver+morphia

    package com.lolaage.dals.dbfactory.mongodb; import java.net.UnknownHostException; import java.util.A ...

随机推荐

  1. Codeforces Round #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )

    B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...

  2. 自动化测试框架selenium+java+TestNG——读取csv文件

    读取csv文件可以直接读取,也可以使用javacsv.jar,后者比较简单,这个也可以变相认为是对表格的处理,我们可以在表格中做好数据,存储成csv格式的文件,后续对xlsx表格的操作抽个时间再记录下 ...

  3. 如何把wecenter的推荐的问题模块单独调取出来?

    查阅文档: http://wenda.wecenter.com/question/1893 http://www.zhidiu.com/article/1012 http://wenda.wecent ...

  4. ansible管理windows实践

    一.前言 近期打算搞搞自动部署,因为是windows服务器,一些工具和系统支持都不是太好.最后发现ansible比较火,最重要的是他支持windows.本文主要就ansible 在windows使用环 ...

  5. 004-画图神器-graphviz

    1 安装及基本使用 1) 下载安装 下载地址 可以下载安装版进行安装或者解压版直接使用 2) 添加系统path 为了能够在dos中使用命令, 需要添加环境变量 默认安装路径为 C:\Program F ...

  6. Linux-用户和权限

    1 Linux所有内容都是文件 归一的思想 面向对象的思想 文件只需要做增删改查的操作 2 延迟读取 一般的文本读取工具都是先将内容全部都读入内存中 cat的机制不同 是读一行显示一行 这与它的功能有 ...

  7. boost replace_if replace_all_regex_copy用法

    #include <boost/algorithm/string.hpp> // for is_any_of #include <boost/range/algorithm/repl ...

  8. 51nod1060:最复杂的数(DFS求反素数)

    把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数.   例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6.如果有多个数复杂度相等,输出最 ...

  9. Python下使用Psyco模块优化运行速度

    今天介绍下Psyco模块,Psyco模块可以使你的Python程序运行的像C语言一样快.都说Python语言易用易学,但性能上跟一些编译语言(如C语言)比较要差不少,这里可以用C语言和Python语言 ...

  10. Fire Game

    Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows ...