The MongoUpdateBatch class

(PECL mongo >=1.5.0)

Introducere

Constructs a batch of UPDATE operations. See MongoWriteBatch.

Sinopsisul clasei

MongoUpdateBatch extends MongoWriteBatch {
/* Metode */
public __construct ( MongoCollection $collection , array $write_options = ? )
/* Metode moștenite */
public MongoWriteBatch::add ( array $item ) : bool
final public MongoWriteBatch::execute ( array $write_options ) : array
}

Cuprins

add a note add a note

User Contributed Notes 2 notes

up
4
jujhar at jujhar dot com
10 years ago
Here's a stackoverflow link showing you how to use this BulkUpdate feature properly and format the updates you add to the class.

http://stackoverflow.com/questions/24753464/mongo-mass-update-to-lower-case

eg.
<?php
$batch
->add(
         array(
            
"q" => array( '_id' => $doc['_id'] ),
            
"u" => array(
                
'$set' => array(
                    
'UserName' => strtolower($doc['UserName'])
                 )
             )
         )
     );
?>
up
1
k4ndar at yahoo dot com
10 years ago
Complete example:

<?php
$mc
= new MongoClient('localhost');
$collection = $mc->selectCollection('blog', 'users');

$update = array(
 
'q' => array('foo' => 'bar'),
 
'u' => array('$set' => array('foo' => 'baz')),
 
'multi' => false,
 
'upsert' => false,
);
$batch = new MongoUpdateBatch($collection);
$batch->add((object) $update);
$batch->execute();
To Top