spring 数据 Mongo db 聚合

巴德·埃丁·本

我使用以下聚合来计算具有特定“alertsources.date_creation”的文档“alert”上的“alertsources”,但我不知道为什么它计算所有alertsources而不是那些具有条件的alertsources:

final Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(Criteria.where("alertsources.date_creation").regex(date)),
                Aggregation.match(Criteria.where("descA").is(alertName)),

                //regex(".*"+date+".*")
                Aggregation.unwind("alertsources"),
                Aggregation.unwind("descA"),
                Aggregation.group().count().as("count"));

        //System.out.println("----------"+mongoTemplate.aggregate(aggregation, Alert.class, MentionCount.class).getRawResults()+"-----");
        List<MentionCount> agregResult = mongoTemplate.aggregate(aggregation, Alert.class, MentionCount.class).getMappedResults();
巴德·埃丁·本

我解决了这个问题,我应该在 $unwind 之前和之后应用 $match :

Aggregation.match(Criteria.where("alertsources.date_creation").regex(".*"+date+".*")),
                Aggregation.match(Criteria.where("descA").is(alertName)),

                //regex(".*"+date+".*")
                Aggregation.unwind("alertsources"),
                Aggregation.unwind("descA"),
                Aggregation.match(Criteria.where("alertsources.date_creation").regex(".*"+date+".*")),
                Aggregation.group().count().as("count")

所有的功劳都归功于@ Neil Lunn,经过研究,我找到了他对此事的原始答案

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

mongo db聚合/ mapreduce

来自分类Dev

带有@Field 注释的 Spring 数据 mongo 聚合

来自分类Dev

在mongo db聚合中使用$ not

来自分类Dev

阵列上的Mongo DB聚合

来自分类Dev

如何在Spring Data Mongo DB中使用聚合使用$ month

来自分类Dev

Mongo DB聚合不起作用

来自分类Dev

是否可以在mongo db中聚合$$ ROOT?

来自分类Dev

Laravel与Mongo DB聚合给我错误

来自分类Dev

带循环的Mongo Db聚合管道

来自分类Dev

在mongo聚合中排除数据

来自分类Dev

使用Spring数据存储库和Mongo DB设置Spring App

来自分类Dev

使用Spring数据存储库和Mongo DB设置Spring App

来自分类Dev

Spring数据存储库聚合

来自分类Dev

MongoDB聚合查询的Spring数据

来自分类Dev

Mongo DB-聚合中两组字段的并集

来自分类Dev

Mongo DB聚合将书籍转换为作者数组

来自分类Dev

mongo db使用集合中的值进行聚合匹配

来自分类Dev

mongo db聚合中$ set的动态字段路径

来自分类Dev

mongo db聚合如何获取所有字段

来自分类Dev

如何使用聚合MongoDB获取数据Mongo数据

来自分类Dev

如何在Spring中编写此Mongo聚合查询?

来自分类Dev

如何使用 for 循环构建 Spring Data Mongo 聚合操作

来自分类Dev

对Mongo聚合查询返回的结果进行重复数据删除

来自分类Dev

使用 mongo 聚合框架计算每个用户的数据

来自分类Dev

将mongo db查询映射到spring

来自分类Dev

Spring boot Mongo DB .yml 配置

来自分类Dev

在Mongo DB中存储数据URL

来自分类Dev

将数据上传到Meteor / Mongo DB

来自分类Dev

将数据上传到Meteor / Mongo DB