You want $filterhere:
useritems.aggregate([
{ "$match": {
"userid": ObjectId(useridhere),
"items.activated": true
}},
{ "$addFields": {
"items": {
"$filter": {
"input": "$items",
"as": "i",
"cond": "$$i.activated"
}
}
}}
],(err,results) => {
});
, , useridhere, mongoose "" " " ObjectId . № 1399, , "", , "".
, :
const ObjectId = require('mongodb').ObjectID;
"" .
, , req.params , ObjectId.
, .aggregate() , , " " - . :
useritems.find({ userid: useridhere, "items.activated": true })
.select('items.$')
.exec((err,items) => {
});
$ "" , - "" .
, "" , $filter, , MongoDB $unwind .
$unwind (Anything past MongoDB 2.4) "" , $group, " ". , , " ", $lookup, .
. $filter.
. $addFields "" . MongoDB , $project . :
{ "$project": {
"userid": 1,
"items": {
"$filter": {
"input": "$items",
"as": "i",
"cond": "$$i.activated"
}
}
}}