Exemple #1
0
 /**
  * Get the javascript shell of update
  * @return string
  */
 public static function update($collection, $newData, $oldData)
 {
     if ($newData !== $oldData) {
         $newDataJson = Convert::document2Json($newData);
         if (empty($oldData)) {
             $newDataStr = Convert::Json2Str($newDataJson);
             return "db.getCollection('{$collection}').insert({$newDataStr});";
         } else {
             $id = $oldData['_id'] . '';
             $oldDataJson = Convert::document2Json($oldData);
             $updateStr = self::_generateShell($newDataJson, $oldDataJson);
             return "db.getCollection('{$collection}').update({'_id': ObjectId('{$id}')},{$updateStr});";
         }
     } else {
         return "";
     }
 }