public function save(&$a, array $options = [])
    {
        $id = $this->ensureDocumentHasMongoId($a);

        $document = (array) $a;

        $options['upsert'] = true;

        try {
            /** @var \MongoDB\UpdateResult $result */
            $result = $this->collection->replaceOne(
                TypeConverter::fromLegacy(['_id' => $id]),
                TypeConverter::fromLegacy($document),
                $this->convertWriteConcernOptions($options)
            );

            if (! $result->isAcknowledged()) {
                return true;
            }

            $resultArray = [
                'ok' => 1.0,
                'nModified' => $result->getModifiedCount(),
                'n' => $result->getUpsertedCount() + $result->getModifiedCount(),
                'err' => null,
                'errmsg' => null,
                'updatedExisting' => $result->getUpsertedCount() == 0 && $result->getModifiedCount() > 0,
            ];
            if ($result->getUpsertedId() !== null) {
                $resultArray['upserted'] = TypeConverter::toLegacy($result->getUpsertedId());
            }

            return $resultArray;
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e);
        }
    }
public function save(&$a, array $options = [])
    {
        $id = $this->ensureDocumentHasMongoId($a);

        $document = (array) $a;

        $options['upsert'] = true;

        try {
            /** @var \MongoDB\UpdateResult $result */
            $result = $this->collection->replaceOne(
                TypeConverter::fromLegacy(['_id' => $id]),
                TypeConverter::fromLegacy($document),
                $this->convertWriteConcernOptions($options)
            );

            if (! $result->isAcknowledged()) {
                return true;
            }

            $resultArray = [
                'ok' => 1.0,
                'nModified' => $result->getModifiedCount(),
                'n' => $result->getUpsertedCount() + $result->getModifiedCount(),
                'err' => null,
                'errmsg' => null,
                'updatedExisting' => $result->getUpsertedCount() == 0 && $result->getModifiedCount() > 0,
            ];
            if ($result->getUpsertedId() !== null) {
                $resultArray['upserted'] = TypeConverter::toLegacy($result->getUpsertedId());
            }

            return $resultArray;
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e);
        }
    }
public function save ( & $ a , array $ options = [ ] ) { $ id = $ this -> ensureDocumentHasMongoId ( $ a ) ; $ document = ( array ) $ a ; $ options [ 'upsert' ] = true ; try { /** @var \MongoDB\UpdateResult $result */ $ result = $ this -> collection -> replaceOne ( TypeConverter :: fromLegacy ( [ '_id' => $ id ] ) , TypeConverter :: fromLegacy ( $ document ) , $ this -> convertWriteConcernOptions ( $ options ) ) ; if ( ! $ result -> isAcknowledged ( ) ) { return true ; } $ resultArray = [ 'ok' => 1.0 , 'nModified' => $ result -> getModifiedCount ( ) , 'n' => $ result -> getUpsertedCount ( ) + $ result -> getModifiedCount ( ) , 'err' => null , 'errmsg' => null , 'updatedExisting' => $ result -> getUpsertedCount ( ) == 0 && $ result -> getModifiedCount ( ) > 0 , ] ; if ( $ result -> getUpsertedId ( ) !== null ) { $ resultArray [ 'upserted' ] = TypeConverter :: toLegacy ( $ result -> getUpsertedId ( ) ) ; } return $ resultArray ; } catch ( \ MongoDB \ Driver \ Exception \ Exception $ e ) { throw ExceptionConverter :: toLegacy ( $ e ) ; } }
Saves an object to this collection

@link http://www.php.net/manual/en/mongocollection.save.php
@param array|object $a Array to save. If an object is used, it may not have protected or private properties.
@param array $options Options for the save.
@throws MongoException if the inserted document is empty or if it contains zero-length keys. Attempting to insert an object with protected and private properties will cause a zero-length key error.
@throws MongoCursorException if the "w" option is set and the write fails.
@throws MongoCursorTimeoutException if the "w" option is set to a value greater than one and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout. The operation in MongoCollection::$wtimeout is milliseconds.
@return array|boolean If w was set, returns an array containing the status of the save.
Otherwise, returns a boolean representing if the array was not empty (an empty array will not be inserted).
Saves an object to this collection