Database

[{"id":"PRODUCT1","name":"Product 1","active":true,"categories":[{"id":"CAT-1","active":true,"subcategories":[{"id":"SUBCAT-1","active":false},{"id":"SUBCAT-2","active":true}]},{"id":"CAT-2","active":false,"subcategories":[{"id":"SUBCAT-3","active":true}]}]}]

Query

db.collection.aggregate([{$redact:{$cond:{if:{$eq:["$active",true]},then:"$$DESCEND",else:"$$PRUNE"}}}])

Result