PhpRiot
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

Updating a document

Updating a document changes the key/value pairs in an existing document. This operation does not share the replace semantics; the values of the keys that are not specified in the data set will not be changed. You must provide both a document key and data, either via a Zend_Cloud_DocumentService_Document document or an array, to this method. If the key is null and a document object is provided, the document key is used.

Example 78. Updating a document

<?php
// update one field
$documents->updateDocument("mydata""DocumentID", array("key2" => "new value"));

// or with document; this could be a document already retrieved from the service
$document = new Zend_Cloud_DocumentService_Document(array(
    
'key1' => 'value1',
    
'key2' => 123,
    
'key3' => 'thirdvalue',
), 
"DocumentID");
$documents->updateDocument("mydata"null$document);

// copy document to another ID
$documents->updateDocument("mydata""AnotherDocumentID"$document);

Amazon SimpleDB supports multi-value fields, so data updates will be merged with the old key value instead of replacing them. Option merge should contain an array of field names to be merged. The array should be key/value pairs, with the key corresponding to the field key, and the value a boolean value indicating merge status (boolean true would merge; false would not). Any keys not specified in the merge option will be replaced instead of merged.

Example 79. Merging document fields

<?php
// key2 is overwritten, key3 is merged
$documents->updateDocument('mydata''DocumentID',
    array(
'key2' => 'new value''key3' => 'additional value'),
    array(
'merge' => array('key3' => true))
);

Zend Framework