How to filter array in each array element of a MongoDB collection?

There is a collection:

[
{
 "name": "Alex",
 "cars": [
{
 "label": "BMW",
 "age": 13,
 "things": [ ... ]
},
{
 "label": "Mercedes",
 "age": 8,
 "things": [ ... ]
}
]
},
 { ... }
]


Need to get a collection without some `thing`s, by condition, using MongoDB aggregations.

Wrote the code:

db.matches.aggregate([{
 $project: {
 '_id': '$_id',
 'cars': {
 $map: {
 input: '$cars',
 as: 'car',
 in: {
 'things': {
 $filter: {
 input: '$$car.things',
 as: 'thing',
 cond: {
 $lte: [ '$$thing.cost', 10 ]
}
}
}
}
}
}
}
}
])


But it requires explicit enumeration of all persistent fields, a list of which real collection varies (unknown). How to be?
July 4th 19 at 23:58
1 answer
July 5th 19 at 00:00
Solution
Can You help $redact?
It seems that Yes, thank you! (I spat and all the manipulation, of such a subject, doing post-processing.) - Elda_Mertz commented on July 5th 19 at 00:03

Find more questions by tags MongoDB