【发布时间】:2022-01-17 10:42:50
【问题描述】:
我实际上需要在 mongoDb 中使用聚合。我已经使用以下查询加入两个集合,然后通过一些过滤器提取答案。查询在 mongodb 终端中运行良好。
但我需要在 Spring Boot 中使用 Aggreagte 函数在 Spring Boot 中使用此查询。我查看了以下文档,这非常有用。但是由于查询很大。这就是为什么我无法以正确的方式编写它。
https://www.baeldung.com/spring-data-mongodb-projections-aggregations
db.coll1.aggregate([
{
"$unionWith": {"coll": "coll2"}
},
{
"$group": {
"_id": {
"Id": "Id",
"Name": {
"$arrayElemAt": [
{
$split: [
"FullName",
"T",
]
},
1
]
},
"StreetName": {
"$arrayElemAt": [
{
$split: [
"Address",
"T",
]
},
1
]
}
},
"count": {
"$sum": 1
}
}
},
{
"$match": {
"$expr": {
"$gt": [
"$count",
1
]
}
}
}])
你能帮我使用aggreagte函数并转换这个查询,以便我可以在springboot中为你做这个。
【问题讨论】:
-
什么版本的spring-data-mongodb? UnionWithOperation 与 3.1 一起添加
标签: mongodb spring-boot aggregation-framework spring-data-mongodb aggregation