6. The Advanced Stuff
6.7. Document Partial Updates
6.6. Write Queries Flags
« Previous
6.8. Massive Partial Updates
Next »

6.7. Document Partial Updates

AuthorDariusz Górecki

Since the v1.3.5 You can do partial updates of documents.

Normally this extension, when using EmongoDocument::save() will always replace all contents of document in DB with the actual values of fields in Yours EMongoDocument instance (including all embedded documents etc.)

You can pass to EMongoDocument::update() method a list of attributes for update, this will use an extreme efficient Mongo $set operator to update only listed fields, see example:

$model = ModelClass::model()->find(); // Find some document to work with
 
// change some fields
$model->field1 = 1;
$model->field2 = 'value';
 
// Optional: run validation, of changed fields:
$model->validate(array('field1', 'field2'));
 
// Use partial update
$model->update(array('field1', 'field2'), true /* <- second parameter indicates to use partial update mechanism */);

And thats it, this will only update those 2 fields, rest in DB will not be touched.

6.7. Document Partial Updates
6. The Advanced Stuff
« Previous
6.6. Write Queries Flags
Next »
6.8. Massive Partial Updates