mongodb - 带分页的 MongoDB 聚合查询
问题描述
我有一个聚合查询
db.getCollection('sell_ProductionRecords').aggregate([
{ $lookup : {
'from': "sell_ProduceRecords",
'localField': "produceID",
'foreignField': "_id",
'as': "produce"
}},
{ $lookup : {
'from': "sell_PackageType",
'localField': "packagingTypeID",
'foreignField': "_id",
'as': "packageType"
}} ,
{ $lookup : {
'from': "sell_Plots",
'localField': "plotID",
'foreignField': "_id",
'as': "plots"
}},
{ $match: { 'plots.plotNumber': "123457" } } ,
{$facet: {
result: [
{ $skip: 0 },
{ $limit: 1 }
],
totalCount: [
{
$count: 'count'
}
]
}}
])
我正在尝试为此创建一个聚合查询
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.lookup("sell_ProduceRecords", "produceID", "_id", "produce"),
Aggregation.lookup("sell_Plots", "plotID", "_id", "plots"),
Aggregation.lookup("sell_PackageType", "packagingTypeID", "_id", "packageType"),
Aggregation.match(new Criteria().andOperator(criteria.toArray(new Criteria[criteria.size()]))),
sort,
Aggregation.facet(
Aggregation.skip(paging.getPageNumber() * paging.getPageSize()),
Aggregation.limit(paging.getPageSize()
)).as("result")
);
但我不知道如何在 facet 中创建总计数。上面的查询对我来说很好,但我不知道如何在 java 中为此创建聚合
解决方案
推荐阅读
- c++ - 尝试使用 OpenMP 并行化此矩阵-矩阵乘法的外循环
- google-apps-script - 使用谷歌应用程序脚本将范围添加到辅助(右)垂直轴上的折线图
- r - 解决 R 中的中级微观经济学问题
- python-3.x - 将项目附加到列表的元素,将其添加到 Python 中列表中的所有元素?
- python-3.x - /usr/bin/ld: 找不到 -lcodec2 安装 pycodec2 时出错
- r - 禁用 actionButton 直到选择了一组新的选项
- javascript - 计时器用完后重定向到主页
- python - flask python 3 TypeError(“'NoneType'对象不可下标”
- assembly - 装配编程输入+5
- javascript - 在无线电类型字段上同时提供 :value 和 v-model