Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring MongoDB:基于日期聚合第一条记录_Java_Mongodb_Spring Data Mongodb_Mongotemplate - Fatal编程技术网

Java Spring MongoDB:基于日期聚合第一条记录

Java Spring MongoDB:基于日期聚合第一条记录,java,mongodb,spring-data-mongodb,mongotemplate,Java,Mongodb,Spring Data Mongodb,Mongotemplate,在我的应用程序中,每周对客户进行评估,我需要他们在特定分支代码和类别中的最新评估 在我的json数据中: 分支代码:customerView.branchCode 类别:cardInfo.\u id 评估日期:date 对象(Json): 在这个示例中,我有两条记录具有相同的customerView.number和cardInfo.\u id,我需要具有5d2d57da43a99e1a5c4728d7 id的对象,因为该日期大于该日期 爪哇: 返回对象: 0 => id = 2

在我的应用程序中,每周对客户进行评估,我需要他们在特定分支代码和类别中的最新评估

在我的json数据中:

分支代码:
customerView.branchCode

类别:
cardInfo.\u id

评估日期:
date

对象(Json):

在这个示例中,我有两条记录具有相同的
customerView.number
cardInfo.\u id
,我需要具有5d2d57da43a99e1a5c4728d7 id的对象,因为该日期大于该日期

爪哇:

返回对象:

0 =>
     id =  2374051 /*customerView.number*/
     date =  "2019-07-15T19:30:00.000Z"
     totalScore = null

任何人都可以帮助我如何在客户编号中获取
totalScore
值?

在组聚合中,
as()
返回链
GroupOption
对象,它可以基于
第一个(…)
最后一个(…)
记录完成其他字段

Aggregation.group("$customerView.number").first("totalScore").as("totalScore").first("date").as("date")
返回对象:

0 =>
    id =  2374051 /*customerView.number*/
    date =  "2019-07-15T19:30:00.000Z"
    totalScore = 11.0

在组聚合中,
as()
返回链
GroupOption
对象,它可以根据
first(…)
last(…)
记录完成其他字段

Aggregation.group("$customerView.number").first("totalScore").as("totalScore").first("date").as("date")
返回对象:

0 =>
    id =  2374051 /*customerView.number*/
    date =  "2019-07-15T19:30:00.000Z"
    totalScore = 11.0
0 =>
    id =  2374051 /*customerView.number*/
    date =  "2019-07-15T19:30:00.000Z"
    totalScore = 11.0