Aggregate.prototype.redact()
Parameters
expression «Object» redact options or conditional expression
[thenExpr] «String|Object» true case for the condition
[elseExpr] «String|Object» false case for the condition
Returns:
- «Aggregate» this
Appends a new $redact operator to this aggregate pipeline.
If 3 arguments are supplied, Mongoose will wrap them with if-then-else of $cond operator respectively If thenExpr
or elseExpr
is string, make sure it starts with , like DESCEND
, PRUNE
or KEEP
.
Example:
Model.aggregate(...)
.redact({
$cond: {
if: { $eq: [ '$level', 5 ] },
then: '$$PRUNE',
else: '$$DESCEND'
}
})
.exec();
// $redact often comes with $cond operator, you can also use the following syntax provided by mongoose
Model.aggregate(...)
.redact({ $eq: [ '$level', 5 ] }, '$$PRUNE', '$$DESCEND')
.exec();
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .