【发布时间】:2020-06-20 03:20:28
【问题描述】:
我想从聚合映射运算符内部在函数级别设置一个变量。这是我到目前为止所拥有的sn-p。
$project: {
collectionId: 1,
name: 1,
description: 1,
image: 1,
created: 1,
updated: 1,
isPresent: "no",
"products": {
$map: {
"input": "$products",
as: "product",
in: {
"title": "$$product.name",
"imageUrl": "$$product.mainImage",
"productId": "$$product.productId",
"$isPresent": "yes"
}
}
},
total: {
$size: "$products"
},
userId: "$user.userId",
userName: "$user.name",
}
我想根据条件在地图运算符中将 isPresent 节点值设置为是。暂时我一直保持“是”。但这不起作用。
有什么办法呢?
【问题讨论】:
-
您想在
productsarray 上检查的条件是什么?也许更好地解释一下产品的哪些案例是父字段isPresent : 'Yes' -
我有一个名为 productId 的局部变量...我正在检查 productId 是否等于 products 数组中的任何 productId。
-
isPresent和$isPresent都有,你指的是哪一个?
标签: mongodb mongoose mongodb-query aggregation-framework