$$DESCEND
The $$DESCEND operator in Amazon DocumentDB is a special positional array operator used within the $redact pipeline stage. It instructs the aggregation pipeline to descend into the current document and process all fields, regardless of their nesting level.
When the $redact stage encounters the $$DESCEND operator, it will keep all the fields in the current document visible and process them further down the pipeline. This is useful when you want to selectively redact or prune certain fields based on a condition, while retaining the structure of the document.
Parameters
None.
Example (MongoDB Shell)
In this example, we'll use the $redact stage with the $$DESCEND operator to selectively display documents where the code field is equal to "Reg".
Create sample documents
db.patient.insertMany([ { "_id": 1, "code": "Emp", "patient": "John Doe", "DOB": "1/1/1980", "Hospital": "Main" }, { "_id": 2, "code": "Reg", "patient": "Jane Doe", "DOB": "3/27/1989", "Hospital": "Cherry Hill" }, { "_id": 3, "code": "Emp", "patient": "Bob Smith", "DOB": "6/15/1975", "Hospital": "Downtown" } ]);
Query example
db.patient.aggregate([ { $redact: { $cond: { if: { $eq: ["Reg", "$code"] }, then: "$$DESCEND", else: "$$PRUNE" } }} ]);
Output
{
"_id": 2,
"code": "Reg",
"patient": "Jane Doe",
"DOB": "3/27/1989",
"Hospital": "Cherry Hill"
}
Code examples
To view a code example for using the $$DESCEND command, choose the tab for the language that you want to use: