请参阅我的数据库查询:
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写。请帮助我如果有人有想法解决这个问题
答案 0 :(得分: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();
}