Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Replacing a document

Replacing a document means removing all document data associated with a particular document key and substituting it with a new set of data. Unlike updating, this operation does not merge old and new data but replaces the document as a whole. The replace operation, like insertDocument(), accepts a Zend_Cloud_DocumentService_Document document or an array of key-value pairs that specify names and values of the new fields, and the collection in which the document exists.

Document ID is required

To replace the document, the document ID is required. Just like inserting a document, if you use an associative array to describe the document, you will need to provide a provider-specific key indicating the document ID. As such, the most compatible way to replace a document across providers is to utilize a Document object, as shown in the examples.

Example 77. Replacing a document

= new Zend_Cloud_DocumentService_Document(array(
'key1' => 'value1',
'key2' => 123,
'key3' => 'thirdvalue',

// Update the document as found in the "mydata" collection

You may also use an existing Document object, re-assign the fields and/or assign new fields, and pass it to the replaceDocument() method:

->key4 '4th value';

// Update the document as found in the "mydata" collection

Zend Framework