private function dispatchModelEvent($action, $collection)
    {
        if (!($this->repository instanceof DocumentRepository)) {
            return;
        }
        if (!method_exists($collection, 'getId')) {
            return;
        }

        $event = new ModelEvent();
        $event->setCollectionId($collection->getId());
        $event->setActionByDispatchName($action);
        $event->setCollectionName($this->repository->getClassMetadata()->getCollection());
        $event->setCollectionClass($this->repository->getClassName());
        $event->setCollection($collection);

        $this->eventDispatcher->dispatch($action, $event);
    }