Просмотр исходного кода

Use existing update method in save()

Andreas Braun 10 лет назад
Родитель
Сommit
4483700a70
1 измененных файлов с 5 добавлено и 5 удалено
  1. 5 5
      lib/Mongo/MongoCollection.php

+ 5 - 5
lib/Mongo/MongoCollection.php

@@ -572,18 +572,18 @@ class MongoCollection
     public function save($a, array $options = [])
     {
         if (is_object($a)) {
-            $a = (array)$a;
+            $a = (array) $a;
         }
+
         if ( ! array_key_exists('_id', $a)) {
             $id = new \MongoId();
         } else {
             $id = $a['_id'];
             unset($a['_id']);
         }
-        $filter = ['_id' => $id];
-        $filter = TypeConverter::convertLegacyArrayToObject($filter);
-        $a = TypeConverter::convertLegacyArrayToObject($a);
-        return $this->collection->updateOne($filter, ['$set' => $a], ['upsert' => true]);
+        $options['upsert'] = true;
+
+        return $this->update(['_id' => $id], ['$set' => $a], $options);
     }
 
     /**