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

2
  • Where is the question? What is the problem? Commented Feb 25, 2016 at 12:46
  • @TimBourguignon how to write modal query using jenssegers/laravel-mongodb package? Commented Feb 26, 2016 at 4:29

1 Answer 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();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply , I have an issue , If I have find condition how to modify this code ?
Can you mention your condition? You can do $comments = Comment::where('votes', '>', 100)->get() . Follow the examples listed here github.com/jenssegers/laravel-mongodb#examples
Yes but I tried it, but at that moment $c is not an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.