Mongodb + Mongoose:$ redact来处理文档访问

时间:2015-02-02 08:36:05

标签: mongodb mongoose

来自官方mongodb文档:http://docs.mongodb.org/manual/reference/operator/aggregation/redact/

我正在使用 $ redact 运算符来按访问标记过滤文档。 在官方指南中,它使用userAccess静态数组来过滤文档。在我的代码中,我会根据所有者字段值使用动态数组

    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);

    });

如何使用表达式 user.followers.id(“$ owner”)来访问所有者值。广告

0 个答案:

没有答案
相关问题