Doctrine\ODM\MongoDB\DocumentManager::getDocumentCollection PHP Method

getDocumentCollection() public method

Returns the MongoCollection instance for a class.
public getDocumentCollection ( string $className ) : Doctrine\MongoDB\Collection
$className string The class name.
return Doctrine\MongoDB\Collection
    public function getDocumentCollection($className)
    {
        $className = ltrim($className, '\\');
        $metadata = $this->metadataFactory->getMetadataFor($className);
        $collectionName = $metadata->getCollection();
        if (!$collectionName) {
            throw MongoDBException::documentNotMappedToCollection($className);
        }
        if (!isset($this->documentCollections[$className])) {
            $db = $this->getDocumentDatabase($className);
            $this->documentCollections[$className] = $metadata->isFile() ? $db->getGridFS($collectionName) : $db->selectCollection($collectionName);
        }
        $collection = $this->documentCollections[$className];
        if ($metadata->slaveOkay !== null) {
            $collection->setSlaveOkay($metadata->slaveOkay);
        }
        return $this->documentCollections[$className];
    }

Usage Example

 protected function tearDown()
 {
     $documentClasses = array('Saxulum\\Tests\\DoctrineMongodbOdmManagerRegistry\\Document\\Document', 'Saxulum\\Tests\\DoctrineMongodbOdmManagerRegistry\\Document\\Category');
     foreach ($documentClasses as $class) {
         $this->dm->getDocumentCollection($class)->drop();
     }
     parent::tearDown();
 }
All Usage Examples Of Doctrine\ODM\MongoDB\DocumentManager::getDocumentCollection