aggregate_group

data:

{

"_id" : ObjectId("57bd128452cb261e9c676a13"),

"_class" : "com.hunterplus.server.position.red_dot.RedDot",

"positionId" : "576b47f4e698010f7c5da670",

"userId" : "5600c0d10cf21f8a9384543b",

"noticeId" : "57bd128252cb261e9c676a12",

"type" : NumberInt(1)

}

{

"_id" : ObjectId("57bd128b52cb261e9c676a15"),

"_class" : "com.hunterplus.server.position.red_dot.RedDot",

"positionId" : "576b47f4e698010f7c5da670",

"userId" : "5600c0d10cf21f8a9384543b",

"noticeId" : "57bd128b52cb261e9c676a14",

"type" : NumberInt(1)

}

{

"_id" : ObjectId("57bd12d752cb260abc53127e"),

"_class" : "com.hunterplus.server.position.red_dot.RedDot",

"positionId" : "576b47f4e698010f7c5da672",

"userId" : "5600c0d10cf21f8a9384543b",

"noticeId" : "57bd128b52cb261e9c676a14",

"type" : NumberInt(1)

}

{

"_id" : ObjectId("57bd39fc52cb261a0c4462cc"),

"_class" : "com.hunterplus.server.position.red_dot.RedDot",

"positionId" : "576b47f4e698010f7c5da670",

"userId" : "5600c0d10cf21f8a9384543b",

"noticeId" : "57bd39fa52cb261a0c4462cb",

"type" : NumberInt(1)

}


Target dto:

public class  RedDotDto {

private  String  positionId;

private  List<String>  noticeIdList;

}


Aggregate 1:


Aggregation aggregation =newAggregation(

match(Criteria.where(RedDot.USER_ID).is(userId)),

project(RedDot.POSITION_ID,RedDot.NOTICE_ID).andExclude(Fields.UNDERSCORE_ID),

group(Fields.UNDERSCORE_ID,RedDot.POSITION_ID).push(RedDot.NOTICE_ID).as(RedDotDto.NOTICE_ID_LIST)

);


result 1 :

返回的数据带有positionId


Aggregate 2

Aggregation aggregation =newAggregation(

match(Criteria.where(RedDot.USER_ID).is(userId)),

project(RedDot.POSITION_ID,RedDot.NOTICE_ID),

group( RedDot.POSITION_ID).push(RedDot.NOTICE_ID).as(RedDotDto.NOTICE_ID_LIST)

);

result 2:


positionId  : null
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,923评论 18 139
  • 环信官方Demo源码分析及SDK简单应用 环信官方Demo源码分析及SDK简单应用-ChatDemoUI3.0 环...
    imGeek阅读 1,605评论 0 3
  • 楔子 不经意瞥到养的小绿芽长高了些,这是颓丧许久后的转折。 小歇说,我不想活的连自己都看不上,我得再为自己拼一把,...
    小歇哎阅读 323评论 0 1
  • 农村有一句俗语叫做“欺山莫欺水”,意思是不管你在陆地上多么牛,都不要轻易下水。我们村有一个叫做八斤的人非常...
    张作霖手黑阅读 719评论 0 0
  • 1.简介 JavaScript 是脚本语言 JavaScript 是一种轻量级的编程语言。 JavaScript ...
    一只写程序的猿阅读 694评论 0 3