public function save($entity, array $options = [])
    {
        // If the "saving" event returns false we'll bail out of the save and return
        // false, indicating that the save failed. This gives an opportunities to
        // listeners to cancel save operations if validations fail or whatever.
        if (false === $this->fireEvent('saving', $entity, true)) {
            return false;
        }

        $data = $this->parseToDocument($entity);

        $queryResult = $this->getCollection()->replaceOne(
            ['_id' => $data['_id']],
            $data,
            $this->mergeOptions($options, ['upsert' => true])
        );

        $result = $queryResult->isAcknowledged() &&
            ($queryResult->getModifiedCount() || $queryResult->getUpsertedCount());

        if ($result) {
            $this->afterSuccess($entity);

            $this->fireEvent('saved', $entity);
        }

        return $result;
    }
public function save($entity, array $options = [])
    {
        // If the "saving" event returns false we'll bail out of the save and return
        // false, indicating that the save failed. This gives an opportunities to
        // listeners to cancel save operations if validations fail or whatever.
        if (false === $this->fireEvent('saving', $entity, true)) {
            return false;
        }

        $data = $this->parseToDocument($entity);

        $queryResult = $this->getCollection()->replaceOne(
            ['_id' => $data['_id']],
            $data,
            $this->mergeOptions($options, ['upsert' => true])
        );

        $result = $queryResult->isAcknowledged() &&
            ($queryResult->getModifiedCount() || $queryResult->getUpsertedCount());

        if ($result) {
            $this->afterSuccess($entity);

            $this->fireEvent('saved', $entity);
        }

        return $result;
    }
public function save ( $ entity , array $ options = [ ] ) { // If the "saving" event returns false we'll bail out of the save and return // false, indicating that the save failed. This gives an opportunities to // listeners to cancel save operations if validations fail or whatever. if ( false === $ this -> fireEvent ( 'saving' , $ entity , true ) ) { return false ; } $ data = $ this -> parseToDocument ( $ entity ) ; $ queryResult = $ this -> getCollection ( ) -> replaceOne ( [ '_id' => $ data [ '_id' ] ] , $ data , $ this -> mergeOptions ( $ options , [ 'upsert' => true ] ) ) ; $ result = $ queryResult -> isAcknowledged ( ) && ( $ queryResult -> getModifiedCount ( ) || $ queryResult -> getUpsertedCount ( ) ) ; if ( $ result ) { $ this -> afterSuccess ( $ entity ) ; $ this -> fireEvent ( 'saved' , $ entity ) ; } return $ result ; }
Upserts the given object into database. Returns success if write concern
is acknowledged.

Notice: Saves with Unacknowledged WriteConcern will not fire `saved` event.

@param mixed $entity  the entity used in the operation
@param array $options possible options to send to mongo driver

@return bool Success (but always false if write concern is Unacknowledged)
Upserts the given object into database . Returns success if write concern is acknowledged .