public function getDocumentCollection(string $className) : Collection
    {
        $className = $this->classNameResolver->getRealClass($className);

        /** @var ClassMetadata $metadata */
        $metadata = $this->metadataFactory->getMetadataFor($className);
        assert($metadata instanceof ClassMetadata);
        if ($metadata->isFile) {
            return $this->getDocumentBucket($className)->getFilesCollection();
        }

        $collectionName = $metadata->getCollection();

        if (! $collectionName) {
            throw MongoDBException::documentNotMappedToCollection($className);
        }

        if (! isset($this->documentCollections[$className])) {
            $db = $this->getDocumentDatabase($className);

            $options = [];
            if ($metadata->readPreference !== null) {
                $options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
            }

            $this->documentCollections[$className] = $db->selectCollection($collectionName, $options);
        }

        return $this->documentCollections[$className];
    }
public function getDocumentCollection(string $className) : Collection
    {
        $className = $this->classNameResolver->getRealClass($className);

        /** @var ClassMetadata $metadata */
        $metadata = $this->metadataFactory->getMetadataFor($className);
        assert($metadata instanceof ClassMetadata);
        if ($metadata->isFile) {
            return $this->getDocumentBucket($className)->getFilesCollection();
        }

        $collectionName = $metadata->getCollection();

        if (! $collectionName) {
            throw MongoDBException::documentNotMappedToCollection($className);
        }

        if (! isset($this->documentCollections[$className])) {
            $db = $this->getDocumentDatabase($className);

            $options = [];
            if ($metadata->readPreference !== null) {
                $options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
            }

            $this->documentCollections[$className] = $db->selectCollection($collectionName, $options);
        }

        return $this->documentCollections[$className];
    }
public function getDocumentCollection ( string $ className ) : Collection { $ className = $ this -> classNameResolver -> getRealClass ( $ className ) ; /** @var ClassMetadata $metadata */ $ metadata = $ this -> metadataFactory -> getMetadataFor ( $ className ) ; assert ( $ metadata instanceof ClassMetadata ) ; if ( $ metadata -> isFile ) { return $ this -> getDocumentBucket ( $ className ) -> getFilesCollection ( ) ; } $ collectionName = $ metadata -> getCollection ( ) ; if ( ! $ collectionName ) { throw MongoDBException :: documentNotMappedToCollection ( $ className ) ; } if ( ! isset ( $ this -> documentCollections [ $ className ] ) ) { $ db = $ this -> getDocumentDatabase ( $ className ) ; $ options = [ ] ; if ( $ metadata -> readPreference !== null ) { $ options [ 'readPreference' ] = new ReadPreference ( $ metadata -> readPreference , $ metadata -> readPreferenceTags ) ; } $ this -> documentCollections [ $ className ] = $ db -> selectCollection ( $ collectionName , $ options ) ; } return $ this -> documentCollections [ $ className ] ; }
Returns the collection instance for a class.

@throws MongoDBException When the $className param is not mapped to a collection.
Returns the collection instance for a class .