0

请查看我的数据库查询:

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 来写。请帮助我如果有人有解决这个问题的想法

4

1 回答 1

1
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();
}
于 2016-02-25T22:00:02.297 回答