Update many document

@param   array   $filters    Filters
@param   array   $update     Update to perform
@param   array   $options    Options
@return  void
337749
public function updateMany($filters, $update, $options = [])
    {
        $result = $this->collection->updateMany($this->castQuery($filters), $update, $options);

        if ($result->isAcknowledged()) {
            return true;
        } else {
            return false;
        }
    }
1293340
public function deleteMany(array $filter, array $options = [])
    {
        $this->writeModels[] = [BulkWrite::DELETE_MANY => [$filter, $options]];

        return $this;
    }
938651
private function doUpdate(array $changes) {
        $db     = $this->db();
        $entity = $this->dao()->getEntityMapping();
        $table  = $entity->getTableName();

        // collect identity infos
        $identity = $entity->getIdentity();
        $idColumn = $identity->getColumn();
        $idValue  = $identity->convertToDBValue($this->getObjectId(), $db);

        // collect version infos
        $versionMapping = $versionName = $versionColumn = $oldVersion = null;
        //if ($versionMapping = $entity->getVersion()) {
        //    $versionName   = $versionMapping->getName();
        //    $versionColumn = $versionMapping->getColumn();
        //    $oldVersion    = $object->getSnapshot()->$versionName;        // TODO: implement dirty check via snapshot
        //    $oldVersion    = $versionMapping->convertToDBValue($oldVersion, $db);
        //}

        // create SQL
        $sql = 'update '.$table.' set';                                     // update table
        foreach ($changes as $name => $value) {                             //    set ...
            $mapping     = $entity->getProperty($name);                     //        ...
            $columnName  = $mapping->getColumn();                           //        ...
            $columnValue = $mapping->convertToDBValue($value, $db);         //        column1 = value1,
            $sql .= ' '.$columnName.' = '.$columnValue.',';                 //        column2 = value2,
        }                                                                   //        ...
        $sql  = strLeft($sql, -1);                                          //        ...
        $sql .= ' where '.$idColumn.' = '.$idValue;                         //    where id = value
        if ($versionMapping) {                                              //        ...
            $op   = $oldVersion=='null' ? 'is':'=';                         //        ...
            $sql .= ' and '.$versionColumn.' '.$op.' '.$oldVersion;         //      and version = oldVersion
        }

        // execute SQL and check for concurrent modifications
        if ($db->execute($sql)->lastAffectedRows() != 1) {
            if ($versionMapping) {
                $this->reload();
                $msg = 'expected version: '.$oldVersion.', found version: '.$this->$versionName;
            }
            else $msg = 'record not found';
            throw new ConcurrentModificationException('Error updating '.get_class($this).' (oid='.$this->getObjectId().'), '.$msg);
        }
        return true;
    }
866949
private function executeUpsert(object $document, array $options) : void
    {
        $options['upsert'] = true;
        $criteria          = $this->getQueryForDocument($document);

        $data = $this->pb->prepareUpsertData($document);

        // Set the initial version for each upsert
        if ($this->class->isVersioned) {
            $versionMapping = $this->class->fieldMappings[$this->class->versionField];
            $nextVersion    = null;
            if ($versionMapping['type'] === 'int') {
                $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
                $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
            } elseif ($versionMapping['type'] === 'date') {
                $nextVersionDateTime = new DateTime();
                $nextVersion         = Type::convertPHPToDatabaseValue($nextVersionDateTime);
                $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
            }
            $data['$set'][$versionMapping['name']] = $nextVersion;
        }

        foreach (array_keys($criteria) as $field) {
            unset($data['$set'][$field]);
            unset($data['$inc'][$field]);
            unset($data['$setOnInsert'][$field]);
        }

        // Do not send empty update operators
        foreach (['$set', '$inc', '$setOnInsert'] as $operator) {
            if (! empty($data[$operator])) {
                continue;
            }

            unset($data[$operator]);
        }

        /* If there are no modifiers remaining, we're upserting a document with
         * an identifier as its only field. Since a document with the identifier
         * may already exist, the desired behavior is "insert if not exists" and
         * NOOP otherwise. MongoDB 2.6+ does not allow empty modifiers, so $set
         * the identifier to the same value in our criteria.
         *
         * This will fail for versions before MongoDB 2.6, which require an
         * empty $set modifier. The best we can do (without attempting to check
         * server versions in advance) is attempt the 2.6+ behavior and retry
         * after the relevant exception.
         *
         * See: https://jira.mongodb.org/browse/SERVER-12266
         */
        if (empty($data)) {
            $retry = true;
            $data  = ['$set' => ['_id' => $criteria['_id']]];
        }

        try {
            assert($this->collection instanceof Collection);
            $this->collection->updateOne($criteria, $data, $options);
            return;
        } catch (WriteException $e) {
            if (empty($retry) || strpos($e->getMessage(), 'Mod on _id not allowed') === false) {
                throw $e;
            }
        }

        assert($this->collection instanceof Collection);
        $this->collection->updateOne($criteria, ['$set' => new stdClass()], $options);
    }
204838
public function update($query, array $options = []) {
		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$query = $params['query'];
			$options = $params['options'];
			$params = $query->export($this);

			list($_path, $conditions) = (array) $params['conditions'];
			$data = $query->data();

			foreach (['id', 'rev'] as $key) {
				$data["_{$key}"] = isset($data[$key]) ? (string) $data[$key] : null;
				unset($data[$key]);
			}
			$data = (array) $conditions + array_filter((array) $data);

			$retry = false;
			do {
				$result = $this->connection->put(
					"{$this->_config['database']}/{$_path}",
					$data,
					['type' => 'json']
				);
				$result = is_string($result) ? json_decode($result, true) : $result;
				$retry = $retry ? !$retry : $this->_autoBuild($result);
			} while ($retry);

			if (isset($result['_id']) || (isset($result['ok']) && $result['ok'] === true)) {
				$result = $this->_format($result, $options);
				$query->entity()->sync($result['id'], ['rev' => $result['rev']]);
				return true;
			}
			if (isset($result['error'])) {
				$query->entity()->errors([$result['error']]);
			}
			return false;
		});
	}
131671
public function addUpdate($condition, $document, $options = [])
    {
        $options = array_merge(
            [
                'multi' => true,
                'upsert' => false,
            ],
            $options
        );

        if ($options['multi']) {
            $keys = array_keys($document);
            if (!empty($keys) && strncmp('$', $keys[0], 1) !== 0) {
                $document = ['$set' => $document];
            }
        }

        $this->document[] = [
            'type' => 'update',
            'condition' => $this->db->getQueryBuilder()->buildCondition($condition),
            'document' => $document,
            'options' => $options,
        ];
        return $this;
    }
802525
public function update($model, $filter = null, array $options = [])
    {
        if (null === $filter) {
            $filter = ['_id' => get_object_id($model)];
        }

        $useOptimisticLock = false;
        if (isset($options['optimistic_lock']) && $options['optimistic_lock']) {
            $useOptimisticLock = true;

            if (false == $version = get_value($model, 'version', false)) {
                throw new \LogicException('The optimistic lock has been requested but version field is not set on the model');
            }

            $filter = array_merge($filter, ['version' => $version]);
        }
        unset($options['optimistic_lock']);

        $originalValues = $this->changesCollector->getOriginalValues($model);
        $values = $this->convertValues->convertToMongoValues(get_values($model, true), $originalValues ?: []);

        $update = $this->changesCollector->changes($values, $originalValues);
        if (empty($update)) {
            return;
        }

        if ($useOptimisticLock) {
            if (false == isset($update['$inc'])) {
                $update['$inc'] = [];
            }

            $update['$inc']['version'] = 1;
        }

        // mongodb's update cannot do a change of existing element and push a new one to a collection.
        $pushUpdate = [];
        $result = null;
        if (array_key_exists('$push', $update)) {
            $pushUpdate['$push'] = $update['$push'];
            unset($update['$push']);

            $this->collection->updateOne($filter, $pushUpdate, $options);

            if ($update) {
                $result = $this->collection->updateOne($filter, $update, $options);
            }
        } else {
            $result = $this->collection->updateOne($filter, $update, $options);
        }

        if ($useOptimisticLock && 0 === $result->getModifiedCount()) {
            throw OptimisticLockException::lockFailed();
        }

        if ($useOptimisticLock) {
            set_value($model, 'version', $version + 1);
        }

        if ($result && $result->getUpsertedCount()) {
            set_object_id($model, new ObjectID((string) $result->getUpsertedId()));
        }

        $this->changesCollector->register($model, $values ?: []);

        return $result;
    }
895586
public function update(array $query, array $newObject, array $options = array())
    {
        return $this->getCollection()->update($query, $newObject, $options);
    }
123058
public function update($options = ['since' => InputOption::VALUE_REQUIRED]) {
    $this->rsyncTemplate();

    $starting_version = $options['since'] ?: $this->currentSchemaVersion;
    if ($this->executeSchemaUpdates($starting_version)) {
      $this->updateSchemaVersionFile();
    }
    $this->cleanup();
    $this->invokeCommand('blt:init:shell-alias');
  }
1030102
public function deleteOne(array $filter, array $options = [])
    {
        $this->writeModels[] = [BulkWrite::DELETE_ONE => [$filter, $options]];

        return $this;
    }
1242735
public function update(array $values, array $options = [])
    {
        // Use $set as default operator.
        if (!Str::startsWith(key($values), '$')) {
            $values = ['$set' => $values];
        }

        // Update multiple items by default.
        if (!array_key_exists('multiple', $options)) {
            $options['multiple'] = true;
        }

        $wheres = $this->compileWheres();

        $result = $this->collection->updateMany($wheres, $values, $options);

        if (1 == (int) $result->isAcknowledged()) {
            return $result->getModifiedCount() ? $result->getModifiedCount() : $result->getUpsertedCount();
        }

        return 0;
    }
1282917
final public function batchUpdate($scn, array $criteria, array $update)
    {
        return $this->getCollectionForModel($scn)->update($criteria, $update, ['multiple' => true]);
    }
43907
public function update($options = array()) {
        $options = new Values($options);

        $data = Values::of(array(
            'FriendlyName' => $options['friendlyName'],
            'Attributes' => $options['attributes'],
            'DateCreated' => Serialize::iso8601DateTime($options['dateCreated']),
            'DateUpdated' => Serialize::iso8601DateTime($options['dateUpdated']),
            'CreatedBy' => $options['createdBy'],
        ));

        $payload = $this->version->update(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new SessionInstance($this->version, $payload, $this->solution['sid']);
    }
1338967
private function perfomOperations($insert, $update, $remove)
    {
        $bulkOperations = [];
        foreach ($insert as $id => $document) {
            $repository = $this->getObjectRepository($document);
            if ($repository instanceof GridFSRepository) {
                $repository->insertOne($document);
                unset($insert[$id]);
            } else {
                $query = $repository->insertOne($document, ['getQuery' => true]);
                $repositoryId = spl_object_hash($repository);
                $bulkOperations[$repositoryId] = isset($bulkOperations[$repositoryId]) ? $bulkOperations[$repositoryId] : $repository->createBulkWriteQuery();
                $bulkOperations[$repositoryId]->addQuery($query);
            }
        }

        foreach ($update as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $query = $repository->updateOne($document, [], ['getQuery' => true]);
            $repositoryId = spl_object_hash($repository);
            $bulkOperations[$repositoryId] = isset($bulkOperations[$repositoryId]) ? $bulkOperations[$repositoryId] : $repository->createBulkWriteQuery();
            $bulkOperations[$repositoryId]->addQuery($query);
        }

        foreach ($remove as $id => $document) {
            $repository = $this->getObjectRepository($document);
            if ($repository instanceof GridFSRepository) {
                $repository->deleteOne($document);
                unset($remove[$id]);
            } else {
                $query = $repository->deleteOne($document, ['getQuery' => true]);
                $repositoryId = spl_object_hash($repository);
                $bulkOperations[$repositoryId] = $bulkOperations[$repositoryId] ?? $repository->createBulkWriteQuery();
                $bulkOperations[$repositoryId]->addQuery($query);
            }
        }

        foreach (array_merge($insert, $update, $remove) as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_PRE_FLUSH, $document);
        }

        foreach ($bulkOperations as $bulkOperation) {
            $bulkOperation->execute();
        }

        foreach (array_merge($insert, $update) as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_POST_FLUSH, $document);
            $repository->cacheObject($document);
        }

        $this->flush();
    }
858237
public function update( $options = [] )
    {

        if ( is_null( $this->row ) ) {
            return $this->reset();
        }

        $mergeOptions = array_replace_recursive( $this->_value, $options );

        $result = WpOption::updateOrCreate(
            ['option_name' => $this->optionsName],
            ['option_value' => json_encode( $mergeOptions )]
        );


        $this->_value = (array) $mergeOptions;

        return $result;

    }
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);
            }
        }
    }
1332270
public function update(array $fields = []) {
        $query = new UpdateQuery($this->getTable());
        $query->fields(!empty($fields)? $fields : $this->getFields());
        $query->whereConditionGroup($this->getWhereConditionGroup());
        return $this->connection->exec($query);
    }