Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Mongodb Odm Bundle

Mongodb Odm Bundle Laravel Package

doctrine/mongodb-odm-bundle

Symfony bundle integrating Doctrine MongoDB ODM for mapping PHP documents to MongoDB. Provides configuration, DI services, console commands, and tooling to manage connections, document managers, and repositories in Symfony apps.

View on GitHub
Deep Wiki
Context7

doctrine/mongodb-odm-bundle integrates the Doctrine MongoDB ODM into the Symfony ecosystem, providing first-class support for mapping PHP documents to MongoDB and managing them through Doctrine’s familiar persistence layer. It offers convenient configuration, service wiring, and tooling so you can build document-centric apps with consistent conventions and minimal boilerplate.

Use it to register document managers, map documents via annotations/attributes/XML/YAML, and leverage Symfony’s container and console for a smooth developer experience.

  • Symfony bundle integration with DI services and configuration
  • Multiple document managers and connections support
  • Mapping drivers for attributes/annotations, XML, and YAML
  • Console commands for schema/index and ODM utilities
  • Event listeners/subscribers and seamless framework tooling
Frequently asked questions about Mongodb Odm Bundle
Can I use doctrine/mongodb-odm-bundle directly in Laravel without Symfony?
No, this bundle is designed for Symfony. However, you can integrate it into Laravel by using Symfony’s Dependency Injection and Console components (via `symfony/dependency-injection` and `symfony/console`) and creating a custom Laravel service provider to bridge the gap. This requires manual setup but unlocks Doctrine ODM’s full feature set.
What Laravel versions support this bundle via Symfony Bridge?
Laravel 10.x+ works best due to its compatibility with Symfony 6.4+. Ensure PHP 8.1+ is used, as Doctrine ODM v3.x (required) mandates this. Older Laravel versions may need additional compatibility layers or Symfony component adjustments.
How do I configure multiple MongoDB connections in Laravel?
You’ll need to extend Symfony’s `doctrine_mongodb.yaml` configuration and bind each connection to Laravel’s service container. Use a custom service provider to register multiple `DocumentManager` instances, each tied to a distinct MongoDB client. Example: define `doctrine_mongodb.odm.default_connection` and `doctrine_mongodb.odm.secondary_connection` in your provider.
Are there Laravel-specific facades or helpers for Doctrine ODM?
No built-in facades exist, but you can create custom ones to wrap ODM operations (e.g., `MongoDB::find()`, `MongoDB::repository()`). Example: extend Laravel’s `Facade` class to delegate calls to the Symfony-registered `DocumentManager`. This improves Laravel’s idiomatic usage while leveraging ODM’s power.
Does this bundle support Laravel migrations for MongoDB schema changes?
No, Laravel’s migration system doesn’t natively support MongoDB. You’ll need to use Doctrine’s CLI commands (`doctrine:mongodb:schema:update`) in your deployment pipeline or create custom Artisan commands. For automation, integrate these commands into Laravel’s `post-deploy` hooks or use a task runner like Laravel Forge.
How do I handle document repositories in Laravel controllers?
Inject the `DocumentManager` or repository services via Laravel’s dependency injection. Example: `public function __construct(private DocumentManager $dm) {}` or resolve repositories via `$dm->getRepository('App\Document\User')`. Ensure your service provider binds these services to Laravel’s container for autowiring.
What are the performance implications of mixing Eloquent and Doctrine ODM?
Performance overhead exists due to dual persistence layers, especially if both query the same data. Doctrine ODM’s query builder is optimized for MongoDB, while Eloquent is SQL-focused. Test thoroughly, as complex joins or transactions may behave differently. Consider caching layers or read replicas to mitigate latency.
Are there alternatives to this bundle for Laravel MongoDB support?
Yes, `jenssegers/mongodb` is a popular Laravel-native package offering simpler MongoDB integration with Eloquent-like syntax. It lacks Doctrine ODM’s advanced features (e.g., complex queries, event listeners) but requires less setup. Evaluate your needs: use `jenssegers/mongodb` for lightweight projects or this bundle for feature-rich ODM workflows.
How do I debug or log Doctrine ODM queries in Laravel?
Enable Doctrine’s logging via Symfony’s `doctrine_mongodb.odm.logger` configuration. Bind a PSR-3 logger (e.g., Monolog) to Laravel’s container and route ODM logs to Laravel’s log channels. Example: configure `monolog.logger.doctrine` in your Symfony bridge setup and ensure Laravel’s `AppServiceProvider` binds it.
What’s the best way to test Doctrine ODM in Laravel’s PHPUnit?
Use Laravel’s `RefreshDatabase` trait with a custom `MongoDBServiceProvider` that resets your MongoDB collections before tests. Mock the `DocumentManager` for unit tests or use in-memory MongoDB (e.g., `mongodb-memory-server`) for integration tests. Example: extend `DatabaseMigrations` to include ODM schema drops in `setUp()`.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport