【发布时间】:2020-06-18 19:44:56
【问题描述】:
我有如下操作的一部分
mongoTemplate.aggregate(
newAggregation(unwind("catalogItems"),
group("catalogItems._id").addToSet("catalogItems.modifierId").as("modIds").addToSet(
new BasicDBObject("_id", "$recipe._id").append("name", "$recipe.name")
.append("menuId", "$recipe.menuId").append("status", "$recipe.status")
.append("modifierList",
new BasicDBObject("modifiers", new BasicDBObject("id", new BasicDBObject("$in", "$modIds")))))
.as("recipeList")),
"table", Ingredient.class).getMappedResults();
这里我要做的是分配包含 $modIds 中的 id 的修饰符。
modifierList - the property I'm going to assign the result with filtered modifiers
modifiers - input list that contains all elements
$modIds - modifier ids got by previous projection
当我尝试这个时,我得到以下错误
Expression $in takes exactly 2 arguments. 1 were passed in.' on server
我认为我的语法不对。但我找不到符合我要求的工作示例。知道怎么做吗?
【问题讨论】:
-
您需要显示使用完整的查询。好像您想搜索
$in文档的字段?在这种情况下,您应该使用Operator expresion -
我已经更新了代码
标签: mongodb mongodb-query aggregation-framework mongotemplate