且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mongodb Java 驱动程序 - 具有多个字段的 $group

更新时间:2023-11-23 08:21:10

我找到了解决方案.我需要将 and 运算符更改为 Projections.fields 运算符.我仍然不知道为什么.也许其他人可以详细说明这一点.

I found the solution. I needed to change the and operator to a Projections.fields operator. I still don't know why. Maybe someon else can elaborate about that.

所以工作查询看起来像这样:

So the working query looks like this:

collectionName.aggregate(
  Arrays.asList(
    group(fields(eq("year", "$year"),
                 eq("month", "$month"),
                 eq("day", "$day"),
                 eq("prodName", "$prodName"),
                 eq("actionName", "$actionName")),
         sum("actionCount", 1))
);