Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update all documents in mongodb PHP

Tags:

php

mongodb

I am setting up a cronjob to update the field views_15 on all documents from collection query.

This is what I had, that should have worked:

    $update = array(
        '$set' => array (
            'views_15' => 0
            )
    );

    $db->queries->update(array(), $update, array('multi' => true));

Also it works for a specific query!

So what should I use instead of array(), from the < query > parameter to select all documents?

like image 974
slownage Avatar asked Sep 08 '26 14:09

slownage


1 Answers

Replace 'multi' with 'multiple' in the options to your update command:

$db->queries->update(array(), $update, array('multiple' => true));

See http://php.net/manual/en/mongocollection.update.php for all the valid update options.

like image 108
Shaun Avatar answered Sep 11 '26 04:09

Shaun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!