0

Please see my database query:

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

I need to write with jenssegers/laravel-mongodb. please help me If anyone has an idea to solve this

KTAnj
  • 1,346
  • 14
  • 36

1 Answers1

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();
}
Ananth
  • 4,227
  • 2
  • 20
  • 26
  • Thanks for the reply , I have an issue , If I have find condition how to modify this code ? – KTAnj Feb 26 '16 at 04:32
  • Can you mention your condition? You can do `$comments = Comment::where('votes', '>', 100)->get()` . Follow the examples listed here https://github.com/jenssegers/laravel-mongodb#examples – Ananth Feb 26 '16 at 05:59
  • Yes but I tried it, but at that moment $c is not an object. – KTAnj Feb 26 '16 at 06:13