Mongolid\DataMapper\DataMapper::insert PHP Method

insert() public method

Notice: Inserts with Unacknowledged WriteConcern will not fire inserted event.
public insert ( mixed $entity, array $options = [], boolean $fireEvents = true ) : boolean
$entity mixed The entity used in the operation.
$options array Possible options to send to mongo driver.
$fireEvents boolean Whether events should be fired.
return boolean Success (but always false if write concern is Unacknowledged)
    public function insert($entity, array $options = [], bool $fireEvents = true) : bool
    {
        if ($fireEvents && $this->fireEvent('inserting', $entity, true) === false) {
            return false;
        }
        $data = $this->parseToDocument($entity);
        $queryResult = $this->getCollection()->insertOne($data, $this->mergeOptions($options));
        $result = $queryResult->isAcknowledged() && $queryResult->getInsertedCount();
        if ($result) {
            $this->afterSuccess($entity);
            if ($fireEvents) {
                $this->fireEvent('inserted', $entity);
            }
        }
        return $result;
    }