文档示例Account的其中一条记录:

// collection: Account
{
"_id" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a"),
"accountType" : "MEMBER",
"money" : NumberLong("10355"),
"lockMoney" : NumberLong("0"),
"periodMoney" : NumberLong("255"),
"payableMoney" : NumberLong("0"),
"incomeMoney" : NumberLong("10355"),
"cost" : NumberLong("1500"),
"costForMonth" : NumberLong("1500"),
"version" : NumberLong("31"),
"periodStartTime" : NumberLong("1480867200000"),
"periodEndTime" : NumberLong("1480953599000"),
"accountRecords" : [
{
"ID" : ObjectId("5843e3e4535f3709061c2141"),
"serial" : ObjectId("5843e3d1535f370902e8dc99"),
"title" : "测试:年跹858啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "PAIDITEMBYNETBANK",
"statementsMessageId" : ObjectId("5843e3e4535f3709061c213f"),
"orderTime" : NumberLong("1480844241849"),
"Money" : NumberLong("800"),
"beforeMoney" : NumberLong("1825"),
"afterMoney" : NumberLong("1825"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843e736535f37092a236725"),
"serial" : ObjectId("5843e6a9535f370927198973"),
"title" : "测试:阳颞愆221啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "PAIDITEMBYNETBANK",
"statementsMessageId" : ObjectId("5843e736535f37092a236723"),
"orderTime" : NumberLong("1480844969902"),
"Money" : NumberLong("300"),
"beforeMoney" : NumberLong("4480"),
"afterMoney" : NumberLong("4480"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843e952535f3709393318c3"),
"serial" : ObjectId("5843e78a535f3709321bce9d"),
"title" : "测试:申铑乔888啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "PAIDITEMBYNETBANK",
"statementsMessageId" : ObjectId("5843e952535f3709393318c1"),
"orderTime" : NumberLong("1480845194664"),
"Money" : NumberLong("400"),
"beforeMoney" : NumberLong("7565"),
"afterMoney" : NumberLong("7565"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843ee2a535f370a49c827d2"),
"serial" : ObjectId("5843ee0d535f370a469c2dde"),
"title" : "测试:燕抒奎85啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "SELL",
"statementsMessageId" : ObjectId("5843ee2a535f370a49c827cd"),
"orderTime" : NumberLong("1480846861000"),
"Money" : NumberLong("255"),
"beforeMoney" : NumberLong("8040"),
"afterMoney" : NumberLong("8295"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843ee2c535f370a49c82880"),
"serial" : ObjectId("5843ee0c535f370a469c2d66"),
"title" : "测试:简鼓禚127啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "SELL",
"statementsMessageId" : ObjectId("5843ee2c535f370a49c8287b"),
"orderTime" : NumberLong("1480846860000"),
"Money" : NumberLong("475"),
"beforeMoney" : NumberLong("8295"),
"afterMoney" : NumberLong("8770"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843ee2c535f370a49c828b2"),
"serial" : ObjectId("5843ee0c535f370a469c2d48"),
"title" : "测试:厍假913啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "SELL",
"statementsMessageId" : ObjectId("5843ee2c535f370a49c828ad"),
"orderTime" : NumberLong("1480846860000"),
"Money" : NumberLong("570"),
"beforeMoney" : NumberLong("8770"),
"afterMoney" : NumberLong("9340"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843ee2d535f370a49c82934"),
"serial" : ObjectId("5843ee0b535f370a469c2ce8"),
"title" : "测试:赖象645啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "SELL",
"statementsMessageId" : ObjectId("5843ee2d535f370a49c8292f"),
"orderTime" : NumberLong("1480846859000"),
"Money" : NumberLong("475"),
"beforeMoney" : NumberLong("9340"),
"afterMoney" : NumberLong("9815"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("5843ee2e535f370a49c82952"),
"serial" : ObjectId("5843ee0b535f370a469c2cd6"),
"title" : "测试:胡滴贻967啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "SELL",
"statementsMessageId" : ObjectId("5843ee2e535f370a49c8294d"),
"orderTime" : NumberLong("1480846859000"),
"Money" : NumberLong("285"),
"beforeMoney" : NumberLong("9815"),
"afterMoney" : NumberLong("10100"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
},
{
"ID" : ObjectId("584542a23da1270a62424b8c"),
"serial" : ObjectId("584542293da1270a5b4a5640"),
"title" : "测试:燕抒奎85啥地方记录卡时间是东风科技为额外认为二位水电费是打发是否是的发生大发上课IE2",
"opertionType" : "SELL",
"statementsMessageId" : ObjectId("584542a23da1270a62424b87"),
"orderTime" : NumberLong("1480933929000"),
"Money" : NumberLong("255"),
"beforeMoney" : NumberLong("10100"),
"afterMoney" : NumberLong("10355"),
"accountId" : ObjectId("5843e38e535f3708f759b25b"),
"memberId" : ObjectId("5843e38e535f3708f759b25a")
}
],
"costMonthFistTimel" : NumberLong("1480521600000")
}

  要查询指定Account账号,并且accountRecords.opertionType="SELL",并且需要按id倒叙,需要分页

mongodb查询语句

db.getCollection("f.publicAccount").aggregate({"$match" : { "memberId" :ObjectId("5843e38e535f3708f759b25a")}})
//.project("gender _id")
.unwind("$accountRecords")
.match({"accountRecords.opertionType" : "SELL"})
.sort({"accountRecords.ID":-1}) .skip(0).limit(3)
.group({ _id:"$_id","accountRecords" : { "$push" : "$accountRecords"}})
;

java morphia代码:

        //指定会员
Query<Accounts> queryMember = this.createQuery().field("memberId").equal(memberId);
Query<Accounts> queryOpertion=queryOpertion =this.createQuery().field("accountRecords.opertionType").in(getIncomeType()); AggregationPipeline pipeline =this.getDs().createAggregation(Accounts.class);
pipeline.match(queryMember);
pipeline.unwind("accountRecords");
//按照入账记录Id排序
pipeline.match(queryOpertion).sort(Sort.descending("accountRecords.ID")).limit(pager.getPageSize()).skip(pager.getSkip());
Accumulator pushFied = Group.push("accountRecords");
pipeline.group("_id",Group.grouping("accountRecords",pushFied));
Iterator<Accounts> iterator = pipeline.aggregate(Accounts.class); if (iterator.hasNext()) {
Accounts account = iterator.next();

  

mongodb 对内嵌文档(数组) group分页查询,并设置查询条件的更多相关文章

  1. mongodb内嵌文档的javaapi,增删改查

    数据结构: {"_id" : "000000001",  //Mongodb默认主键 "UID" : "000000001&quo ...

  2. MongoDB 内嵌文档

    MongoDB是文档型的数据库系统,doc是MongoDB的数据单位,每个doc相当于关系型数据库的数据行(row),doc和row的区别在于field的原子性:row中的column是不和分割的原子 ...

  3. Mongo对内嵌文档的CRUD

    { "_id" : ObjectId("5706032acd0a6194868cf53e"), "list" : { "age&q ...

  4. mongodb内嵌文档的查询

    本文转自:http://blog.163.com/wm_at163/blog/static/1321734902012526103825481/ 1 > db.blog.findOne() { ...

  5. MongoDB内嵌文档操作

    实体定义: [BsonIgnoreExtraElements] public class Person : BaseEntity { public string FirstName { get; se ...

  6. C# mongodb中内嵌文档数组条件查询

    样例数据: {      "_id" : "1064621564857",      "cNo" : "1064621564857 ...

  7. 学习MongoDB 五: MongoDB查询(数组、内嵌文档)(二)

    一.简介 我们上一篇介绍了db.collection.find()可以实现根据条件查询和指定使用投影运算符返回的字段省略此参数返回匹配文档中的所有字段,我们今天介绍了对数组和内嵌文档的查询操作,尤其是 ...

  8. MongoDB-4: 查询(二-数组、内嵌文档)

    一.简介 我们上一篇介绍了db.collection.find()可以实现根据条件查询和指定使用投影运算符返回的字段省略此参数返回匹配文档中的所有字段,我们今天介绍了对数组和内嵌文档的查询操作,尤其是 ...

  9. mongodb对数组元素及内嵌文档进行增删改查操作(转)

    from:https://my.oschina.net/132722/blog/168274 比如我有一个user类,他包含一个标签属性,这个标签是一个数组,数组里面的元素是内嵌文档,格式如下: &l ...

随机推荐

  1. GIS的发展

    2016年2月15日,博客园的blog申请成功了,这是我的第一篇随笔,发一个GIS的发展的视频链接 http://buluo.qq.com/p/detail.html?bid=15060&pi ...

  2. NPOI 单元格(cell) 格式参数

    NPOI 单元格(cell) 将格式设为文本 在网上找了很久,都没有关于如何设置的信息,没办法查了下NPOI的源码终于找到了方法.这里共享下,就是“@”参数 ICellStyle cellStyle ...

  3. linux中模块的构建,传参,和printk函数的简单使用

    静态编译,动态加载应用想访问内核需要通过系统调用 驱动:1.模块(打包,加入内核)2.内核机制3.操作硬件 在Kconfig里面配置menuconfig的时候,不同的类型会在图形化界面的终端显示不用的 ...

  4. TIOBE 2015年7月编程语言排行榜:C++的复兴

    TIOBE 2015年7月编程语言排行榜:C++的复兴 发表于2015-07-13 17:03| 16086次阅读| 来源CSDN| 128 条评论| 作者钱曙光 编程语言排行榜TIOBEC++ 摘要 ...

  5. CoInitialize浅析一

    大家都知道程序中若要使用COM组件则必须要先调用CoInitialize,该函数主要是用来初始化COM运行环境.但这个函数的作用域是以线程为单位还是以进程为单位呢?也许大家已经通过测试程序摸索出答案, ...

  6. C++学习笔记27:异常处理机制

    一.异常处理机制基础 异常的定义 程序中可以检测的运行不正常的情况 异常处理的基本流程 某段程序代码在执行操作时发生特殊情况,引发一个特定的异常 另一段程序代码捕获该异常并处理它 二.异常的引发 th ...

  7. haslayout

    什么是 haslayout ? haslayout 是Windows Internet Explorer渲染引擎的一个内部组成部分.在Internet Explorer中,一个元素要么自己对自身的内容 ...

  8. devexpress xaf 开发中遇到的问题.

    devexpress xaf 开发中遇到的问题很多久了就忘记了.每天都把开发内容记录下来,方便大家,方便自己

  9. IE8利用setCapture和releaseCapture解决iframe的拖拽事件

    最近有个需求须要实现左右拖拽功能,页面右边是个iframe页面,在chrome测试通过之后,发现在ie8上面效果不是很理想,最后查找资料得知可以使用ie自带的setCapture和releaseCap ...

  10. Hyper-V安装Oracle Linux6_4 Oracle db 12c并使用rman做异机恢复

    本文记录在Windows Server 2012 R2上安装Oracle Enterprise Linux 6.4以及使用RMAN进行进行异机恢复的过程. Windows服务器增加Hyper-V功能 ...