private function internalInsert()
    {
        if ($this->triggerEvent(self::EVENT_NAME_BEFORE_INSERT)->isCancelled()) {
            return;
        }

        $document = $this->toArray();

        // try write document
        try {
            $this
                ->collection
                ->getMongoCollection()
                ->insert($document);
        } catch (\Exception $e) {
            throw new WriteException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        // set id
        $this->defineId($document['_id']);

        // after insert event
        $this->triggerEvent(self::EVENT_NAME_AFTER_INSERT);
    }
private function internalInsert()
    {
        if ($this->triggerEvent(self::EVENT_NAME_BEFORE_INSERT)->isCancelled()) {
            return;
        }

        $document = $this->toArray();

        // try write document
        try {
            $this
                ->collection
                ->getMongoCollection()
                ->insert($document);
        } catch (\Exception $e) {
            throw new WriteException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        // set id
        $this->defineId($document['_id']);

        // after insert event
        $this->triggerEvent(self::EVENT_NAME_AFTER_INSERT);
    }
private function internalInsert ( ) { if ( $ this -> triggerEvent ( self :: EVENT_NAME_BEFORE_INSERT ) -> isCancelled ( ) ) { return ; } $ document = $ this -> toArray ( ) ; // try write document try { $ this -> collection -> getMongoCollection ( ) -> insert ( $ document ) ; } catch ( \ Exception $ e ) { throw new WriteException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } // set id $ this -> defineId ( $ document [ '_id' ] ) ; // after insert event $ this -> triggerEvent ( self :: EVENT_NAME_AFTER_INSERT ) ; }
Internal method to insert document
Internal method to insert document