title: Mongodb+Mongoose: $redact to handle document access
body: <p>From official mongodb documentation: <a href="http://docs.mongodb.org/manual/reference/operator/aggregation/redact/" rel="nofollow">http://docs.mongodb.org/manual/reference/operator/aggregation/redact/</a></p>
  
  <p>I'm using <strong>$redact</strong> operator to filter documents by access-tags. <strong>In the official guide it uses userAccess static array</strong> to filter documents. In my code <strong>I would you use a dynamic array based on the owner field value</strong>.</p>
  
  <pre><code>    Data.aggregate([
       { $match: {owner: {$in: followings}}},
       { $redact:
           {
              $cond:
                 {
                   if: { $gt: [ { $size: { $setIntersection: [ "$circles", user.followers.id("$owner").circles ] } }, 0 ] },
                   then: "$$DESCEND",
                   else: "$$PRUNE"
                 }
           }
       }
     ], function(err,result) {
          if(err)
              return next(err);
  
          console.log(result);
  
      });
  </code></pre>
  
  <p>How can I access to <strong>owner</strong> value with expression <strong>user.followers.id("$owner").circles</strong>?</p>