Вы можете использовать $addFields
конвейер агрегации с $filter
для фильтрации поля variants
по isDeleted
конвейер агрегации
db.t4.aggregate([
{$addFields : {
varients : {$filter : {
input :"$varients",
as : "v",
cond : {$not : "$$v.isDeleted"}
}}
}}
])
сбор образцов
> db.t4.findOne()
{
"_id" : "5c1d023422ffef2282619192",
"title" : "Iphone 6S",
"varients" : [
{
"isDeleted" : false,
"_id" : "5c1d023422ffef2282619196",
"title" : "Iphone 6S black 64GB"
},
{
"isDeleted" : true,
"_id" : "5c1d023422ffef2282619193",
"title" : "Iphone 6S green 32GB"
}
]
}
результат
> db.t4.aggregate({$addFields : {varients : {$filter : {input :"$varients", as : "v", cond : {$not : "$$v.isDeleted"}}}}}).pretty()
{
"_id" : "5c1d023422ffef2282619192",
"title" : "Iphone 6S",
"varients" : [
{
"isDeleted" : false,
"_id" : "5c1d023422ffef2282619196",
"title" : "Iphone 6S black 64GB"
}
]
}
>