content_image/689385.jpg
<img src='content_image/689385.jpg'>

To store the access criteria data, add a field to the documents and embedded documents. To allow for multiple com- binations of access levels for the same data, consider setting the access field to an array of arrays. Each array element contains a required set that allows a user with that set to access the data. 

Then, include the $redact stage in the db.collection.aggregate() operation to restrict contents of the result set based on the access required to view the data. 

For more information on the $redact pipeline operator, including its syntax and associated system variables as well as additional examples, see $redact . 

## Procedure 

For example, a forecasts collection contains documents of the following form where the tags field determines the access levels required to view the data: 

{ _id: 1, title: "123 Department Report", tags: [ [ "G" ], [ "FDW" ] ], year: 2014, subsections: [ { subtitle: "Section 1: Overview", tags: [ [ "SI", "G" ], [ "FDW" ] ], content: "Section 1: This is the content of section 1." }, { subtitle: "Section 2: Analysis", tags: [ [ "STLW" ] ], 

