【发布时间】:2019-08-29 03:20:14
【问题描述】:
我有员工数据的 mongo 集合 - 需要在应用过滤器后将数据带入分页,这适用于聚合 - 但我缺少现有的员工总数。
我尝试了 FacetOperation - 它不允许分组操作或计数操作。我有工作的 mongo 查询,它可以正确地为我提供数据 - 我需要将其转换为 spring 数据
db.data.aggregate([
{
"$facet": {
"totalData": [
{
"$match": {
"DatabaseId": "Abcdefg"
}
},
{
"$skip": 0
},
{
"$limit": 15
},
{
"$sort": {
"typeCount.error": 1
}
},
{
"$project": {
"id": 1,
"personalData": 1,
"typeCount": 1,
"messages": 1,
"updatedDate": 1,
"updatedBy": 1
}
}
],
"totalCount": [
{
"$count": "count"
}
]
}
}
])
我有这样的 Spring 数据
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(
Criteria.where("DatabaseId").is(Abcdefg)),
Aggregation.skip(filter.page * filter.pageSize as long),
Aggregation.limit(filter.pageSize),
Aggregation.project("id",
"personalData",
"typeCount",
"messages",
"updatedDate",
"updatedBy",
))
现在我需要将最后一部分添加到此代码中:获取总数
【问题讨论】:
标签: mongodb spring-data