Updates a single document

@param	string	$collection		the collection name
@param	array	$data			an associative array of values, array(field => value)
@param	array	$options		an associative array of options
@usage	$mongodb->update('foo', $data = array());
553172
public function update($collection = '', $data = array(), $options = array(), $literal = false)
		{
			if (empty($collection)) {
				throw new Exception("No Mongo collection selected to update");
			}

			if (empty($data) or ! Arrays::is($data)) {
				throw new Exception("Nothing to update in Mongo collection or update value is not an array");
			}

			try {
				$options = array_merge($options, array('fsync' => true, 'multiple' => false));

				$this->db->{$collection}->update($this->wheres, (($literal) ? $data : array('$set' => $data)), $options);

				$this->_clear();

				return true;
			} catch (\MongoCursorException $e) {
				throw new Exception("Update of data into MongoDB failed: {$e->getMessage()}", $e->getCode());
			}
		}
374529
public function update(array $data, $field, $id)
    {
        $this->applyCriteria();

        /** @var Model $model */
        $model = $this->model->where($field, $id)->first();

        $model->fill($data)->save();

        return $model;
    }
78724
private function createItems(Collection $collection, array $collectionItemsData): void
    {
        foreach ($collectionItemsData as $collectionItemData) {
            $itemDefinition = $this->itemDefinitionRegistry->getItemDefinition($collectionItemData['value_type']);

            $item = $this->cmsItemLoader->loadByRemoteId(
                $collectionItemData['value'],
                $collectionItemData['value_type']
            );

            $itemCreateStruct = $this->collectionService->newItemCreateStruct(
                $itemDefinition,
                $item->getValue()
            );

            $this->setConfigStructs(
                $itemCreateStruct,
                $itemDefinition,
                $collectionItemData['configuration'] ?? []
            );

            $this->collectionService->addItem($collection, $itemCreateStruct, $collectionItemData['position']);
        }
    }
667330
public function createDocument($collection, array $data, array $options = [])
    {
        $this->setOptions($options);
        $doc = new Document($this->client, $this->database, $collection);
        $doc->setHeaders($this->getHeaders());
        $rs = $doc->create($data);
        $this->checkResponse($rs);
        unset($rs['_curl_info']);

        return $rs;
    }
864221
public function updateMany(array $filter, $update, array $options = [])
    {
        list($bulkOptions, $options) = self::extractBulkWriteOptions($options);
        $model = new UpdateMany($filter, $update, $options);

        $bulkWriteResult = $this->bulkWrite([$model], $bulkOptions);

        return new UpdateResult($bulkWriteResult);
    }
1060152
public function update($collectionName, array $data, array $where)
    {
        $collection = $this->db->selectCollection($this->dbName, $collectionName);
        return $collection->update($where, $data);
    }
1068383
public function save(array &$data, array $options = array())
    {
        $document = new Document($data, $this);
        $save = $document->save($options);
        $data = $document->data;

        return $save;
    }
29984
public function update($query, $data, $option = array())
    {
        return $this->collection->update($query, $data, $option);
    }
172976
public function update(Closure $filter, array $data, string $idField = 'id')
    {
        unset($data[$idField]);
        $collectionData = $this->storage->load(true);
        if (!isset($collectionData['items'])) {
            $collectionData['items'] = [];
        }
        $items = &$collectionData['items'];
        foreach ($items as $k => $item) {
            if ($filter($item)) {
                $items[$k] = \array_merge($item, $data);
            }
        }
        $this->storage->save($collectionData);
    }
266845
public function apply(array $options = [])
    {
        $data = [
            'body' => [
                'properties' => $this->mapping
            ]
        ];

        $this->collection->getKuzzle()->query(
            $this->collection->buildQueryArgs('collection', 'updateMapping'),
            $this->collection->getKuzzle()->addHeaders($data, $this->headers),
            $options
        );

        return $this->refresh($options);
    }
115565
public function update($table, $data, $keys, $options = []) {
		return $this->object->update($table, $data, $keys, $options);
	}
1344451
public function update($document, array $options = array())
    {
        $update = $this->pb->prepareUpdateData($document);

        $query = $this->getQueryForDocument($document);

        foreach (array_keys($query) as $field) {
            unset($update['$set'][$field]);
        }

        if (empty($update['$set'])) {
            unset($update['$set']);
        }

        if ( ! empty($update)) {
            // Include versioning logic to set the new version value in the database
            // and to ensure the version has not changed since this document object instance
            // was fetched from the database
            if ($this->class->isVersioned) {
                $versionMapping = $this->class->fieldMappings[$this->class->versionField];
                $currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
                if ($versionMapping['type'] === 'int') {
                    $nextVersion = $currentVersion + 1;
                    $update['$inc'][$versionMapping['name']] = 1;
                    $query[$versionMapping['name']] = $currentVersion;
                    $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
                } elseif ($versionMapping['type'] === 'date') {
                    $nextVersion = new \DateTime();
                    $update['$set'][$versionMapping['name']] = new \MongoDate($nextVersion->getTimestamp());
                    $query[$versionMapping['name']] = new \MongoDate($currentVersion->getTimestamp());
                    $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
                }
            }

            // Include locking logic so that if the document object in memory is currently
            // locked then it will remove it, otherwise it ensures the document is not locked.
            if ($this->class->isLockable) {
                $isLocked = $this->class->reflFields[$this->class->lockField]->getValue($document);
                $lockMapping = $this->class->fieldMappings[$this->class->lockField];
                if ($isLocked) {
                    $update['$unset'] = array($lockMapping['name'] => true);
                } else {
                    $query[$lockMapping['name']] = array('$exists' => false);
                }
            }

            $result = $this->collection->update($query, $update, $options);

            if (($this->class->isVersioned || $this->class->isLockable) && ! $result['n']) {
                throw LockException::lockFailed($document);
            }
        }
    }
1313504
public function update(object $document, array $options = []) : void
    {
        $update = $this->pb->prepareUpdateData($document);

        $query = $this->getQueryForDocument($document);

        foreach (array_keys($query) as $field) {
            unset($update['$set'][$field]);
        }

        if (empty($update['$set'])) {
            unset($update['$set']);
        }

        // Include versioning logic to set the new version value in the database
        // and to ensure the version has not changed since this document object instance
        // was fetched from the database
        $nextVersion = null;
        if ($this->class->isVersioned) {
            $versionMapping = $this->class->fieldMappings[$this->class->versionField];
            $currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
            if ($versionMapping['type'] === 'int') {
                $nextVersion                             = $currentVersion + 1;
                $update['$inc'][$versionMapping['name']] = 1;
                $query[$versionMapping['name']]          = $currentVersion;
            } elseif ($versionMapping['type'] === 'date') {
                $nextVersion                             = new DateTime();
                $update['$set'][$versionMapping['name']] = Type::convertPHPToDatabaseValue($nextVersion);
                $query[$versionMapping['name']]          = Type::convertPHPToDatabaseValue($currentVersion);
            }
        }

        if (! empty($update)) {
            // Include locking logic so that if the document object in memory is currently
            // locked then it will remove it, otherwise it ensures the document is not locked.
            if ($this->class->isLockable) {
                $isLocked    = $this->class->reflFields[$this->class->lockField]->getValue($document);
                $lockMapping = $this->class->fieldMappings[$this->class->lockField];
                if ($isLocked) {
                    $update['$unset'] = [$lockMapping['name'] => true];
                } else {
                    $query[$lockMapping['name']] = ['$exists' => false];
                }
            }

            $options = $this->getWriteOptions($options);

            assert($this->collection instanceof Collection);
            $result = $this->collection->updateOne($query, $update, $options);

            if (($this->class->isVersioned || $this->class->isLockable) && $result->getModifiedCount() !== 1) {
                throw LockException::lockFailed($document);
            } elseif ($this->class->isVersioned) {
                $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
            }
        }

        $this->handleCollections($document, $options);
    }
930566
public function executeUpdate(MongoCollection $collection, Query $query) {
        $where = $this->formatWhere($query->getWhere());
        $fields = $this->formatFields($query);

        $query->attribute([
            'upsert' => false,
            'multiple' => ($query->getLimit() != 1) // multiple in PHP, multi in Mongo
        ]);

        $response = $collection->update($where, $fields, $query->getAttributes() + ['w' => 1]);
        $response['params'] = [
            'where' => $where,
            'fields' => $fields
        ];

        return $response;
    }
257181
public function update($collectionName, array $criteria, array $data, array $options = []) {
		$collection = $this->getCollection($collectionName);
		
		if ($this->_profilerEnabled) {
			$message = 'db.' . $collectionName . '.update(' .
				json_encode($criteria) . ',' . 
				json_encode($data) . ');';

			$event = $this->getProfiler()->startWrite($message);
		}

		$result  = $collection->update($criteria, $data, $options);
		$success = (bool) $result['ok'];
		
		if ($this->_profilerEnabled) {
			$success
				? $event->stopSuccess()
				: $event->stopError();
		}
		
		return $success;
	}
996044
public function mutate($updateQuery, $options = array())
    {
        if(!is_array($updateQuery)) throw new \Exception('$updateQuery should be an array');
        if(!is_array($options)) throw new \Exception('$options should be an array');

        $default = array(
            'w' => 1
        );
        $options = array_merge($default, $options);

        try {
            $this->_connection->update($this->collectionName(), array('_id' => $this->cleanData['_id']), $updateQuery, $options);
        } catch (\MongoCursorException $e) {
            return false;
        }

        return true;
    }
42536
public function createCollection($collection, $options = [])
    {
        if (is_array($collection)) {
            list($database, $collectionName) = $collection;
        } else {
            $database = null;
            $collectionName = $collection;
        }
        $this->beginProfile($token = "    > create collection " . $this->composeCollectionLogName($collection) . " ...");
        $this->db->getDatabase($database)->createCollection($collectionName, $options);
        $this->endProfile($token);
    }