Mongolid\DataMapper\DataMapper::firstOrFail PHP Method

firstOrFail() public method

Retrieve one $this->schema->entityClass objects that matches the given query. If no document was found, throws ModelNotFoundException.
public firstOrFail ( mixed $query = [], array $projection = [], boolean $cacheable = false ) : mixed
$query mixed MongoDB query to retrieve the document.
$projection array Fields to project in Mongo query.
$cacheable boolean Retrieves the first through a CacheableCursor.
return mixed First document matching query as an $this->schema->entityClass object
    public function firstOrFail($query = [], array $projection = [], bool $cacheable = false)
    {
        if ($result = $this->first($query, $projection, $cacheable)) {
            return $result;
        }
        throw (new ModelNotFoundException())->setModel($this->schema->entityClass);
    }