If you are developing a bundle that contains Doctrine MongoDB documents, you must register your mappings so the application's DocumentManager can recognize them.
To simplify this, DoctrineMongoDBBundle provides the DoctrineMongoDBMappingsPass compiler pass. You should register this pass within your bundle's build() method.
When configuring the pass, you must provide:
- An array of mappings where the key is the directory path to your mapping files and the value is the document namespace.
- A parameter name that specifies which
DocumentManager should use these mappings. - A parameter name (boolean) that acts as a feature flag; the mappings will only be enabled if this parameter is set to
true.
namespace Awesome\AwesomeBundle;
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AwesomeBundle extends Bundle
{
public function build(ContainerBuilder $container): void
{
parent::build($container);
// The path to your mapping files
$mappings = [
__DIR__.'/Resources/config/doctrine-mapping' => 'Awesome\AwesomeBundle\Model',
];
$container->addCompilerPass(
DoctrineMongoDBMappingsPass::createXmlMappingDriver(
$mappings,
['awesome_bundle.model_manager_name'],
'awesome_bundle.backend_type_mongodb'
)
);
}
}