map() Mongo 数据库查询 - jenssegers/laravel-mongodb

map() Mongo db Query - jenssegers/laravel-mongodb

请看我的数据库查询:

db.comments
    .find({})
    .forEach(function(doc) { 
                        doc.comments.map(function(c) {
                                if (c.active == 1) {
                                    c.status = 0;
                                 }
                        }); 
                        db.comments.update(
                                      {_id: doc._id}, 
                                      {$set: {comments: doc.comments}});
     });

我需要用 jenssegers/laravel-mongodb 写作。请帮助我如果有人有解决这个问题的想法

class Comment extends Eloquent {}

$comments = Comment::all();
foreach ($comments as $c) {
    $c->comments = array_map(function (&$com) {
        if ($com->active == 1) $com->status = 0;
    }, $c->comments);
    $c->save();
}