src/Factory/RepositoryFactory.php
private function createCollection(DocumentManager $documentManager, ClassMetadata $classMetadata, $collectionName)
    {

        $database = $documentManager->getDatabase();

        $exists = false;
        foreach ($database->listCollections() as $collection) {
            if ($collection->getName() == $collectionName) {
                $exists = true;
            }
        }

        $creationOptions = $classMetadata->getCollectionCreationOptions();
        if (!empty($creationOptions) && !$exists) {
            $database->createCollection($collectionName, $creationOptions);
        }

        $collectionOptions = $classMetadata->getCollectionOptions();

        return $database->selectCollection($collectionName, $collectionOptions);
    }
private function createCollection(DocumentManager $documentManager, ClassMetadata $classMetadata, $collectionName)
    {

        $database = $documentManager->getDatabase();

        $exists = false;
        foreach ($database->listCollections() as $collection) {
            if ($collection->getName() == $collectionName) {
                $exists = true;
            }
        }

        $creationOptions = $classMetadata->getCollectionCreationOptions();
        if (!empty($creationOptions) && !$exists) {
            $database->createCollection($collectionName, $creationOptions);
        }

        $collectionOptions = $classMetadata->getCollectionOptions();

        return $database->selectCollection($collectionName, $collectionOptions);
    }
private function createCollection ( DocumentManager $ documentManager , ClassMetadata $ classMetadata , $ collectionName ) { $ database = $ documentManager -> getDatabase ( ) ; $ exists = false ; foreach ( $ database -> listCollections ( ) as $ collection ) { if ( $ collection -> getName ( ) == $ collectionName ) { $ exists = true ; } } $ creationOptions = $ classMetadata -> getCollectionCreationOptions ( ) ; if ( ! empty ( $ creationOptions ) && ! $ exists ) { $ database -> createCollection ( $ collectionName , $ creationOptions ) ; } $ collectionOptions = $ classMetadata -> getCollectionOptions ( ) ; return $ database -> selectCollection ( $ collectionName , $ collectionOptions ) ; }
Create the collection

@param   DocumentManager     $documentManager    Current document manager
@param   ClassMetadata       $classMetadata      Class metadata
@param   string              $collectionName     Name of collection
@return  Collection
Create the collection