Advertisement
Guest User

Untitled

a guest
Jun 12th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. <?php
  2.  
  3. $cursor = $collection->find(array(), array('news' => 1));
  4.  
  5. // See: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-{{snapshot%28%29}}
  6. $cursor->snapshot();
  7.  
  8. foreach ($cursor as $document) {
  9.     $collection->update(
  10.         array('_id' => $document['_id']),
  11.         array('$set' => array('sum' => array_sum($document['news']))),
  12.         array('multiple' => false)
  13.     );
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement