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
Laravel Mongodb

Laravel Mongodb Laravel Package

mongodb/laravel-mongodb

MongoDB integration for Laravel Eloquent and query builder. Extends core Laravel classes to use the same familiar API with MongoDB. Official mongodb/laravel-mongodb package, compatible with Laravel 10.x; docs and releases maintained by MongoDB.

View on GitHub
Deep Wiki
Context7

mongodb/laravel-mongodb brings first-class MongoDB support to Laravel Eloquent and the Query Builder by extending Laravel’s native classes, so you can keep the familiar API while working with MongoDB collections. Maintained by MongoDB, Inc., it targets Laravel 10.x and integrates cleanly with typical Laravel application patterns.

  • Eloquent model enhancements tailored for MongoDB documents
  • Query Builder support using the standard Laravel method set
  • Drop-in usage with minimal changes to existing Laravel code
  • Official docs and support channels via MongoDB
  • Signed release tags for improved release integrity verification
Frequently asked questions about Laravel Mongodb
How do I install mongodb/laravel-mongodb in a Laravel 10.x project?
Run `composer require mongodb/laravel-mongodb` in your project directory. The package auto-discovers Laravel and integrates with Eloquent and Query Builder without additional configuration. Ensure your `config/database.php` includes a MongoDB connection.
Can I use Eloquent relationships (e.g., hasMany) with MongoDB documents?
Yes, the package supports Laravel’s standard relationships like `hasOne`, `hasMany`, and polymorphic relationships. For embedded documents, use `hasOne` with `embed()` or `embedOne()` methods. One-to-many relationships work but may require denormalization for complex queries.
Does mongodb/laravel-mongodb support Laravel Scout for full-text search?
Yes, the package integrates with Scout using MongoDB’s Atlas Search or the legacy Scout driver. Configure your `config/scout.php` to use the MongoDB engine, and leverage MongoDB’s advanced text search capabilities like fuzzy matching and synonyms.
What Laravel versions does mongodb/laravel-mongodb officially support?
The package officially supports Laravel 10.x–13.x (as of v5.7.0). For older versions (e.g., Laravel 9.x), use v4.x or earlier releases. Check the [GitHub releases](https://github.com/mongodb/laravel-mongodb/releases) for version-specific compatibility notes.
How do I handle soft deletes in MongoDB with this package?
Soft deletes were deprecated in v5.x. Use MongoDB’s TTL indexes for automatic document expiration or implement custom logic with `deleted_at` fields. For existing models, migrate to TTL indexes via `Schema::create()` or manual queries.
Can I use MongoDB transactions with this package?
Yes, the package supports MongoDB’s multi-document ACID transactions. Use Laravel’s `DB::transaction()` or the Query Builder’s `getMongoClient()->startSession()`. Note transactions have performance trade-offs; avoid long-running or parallel operations.
What are the performance considerations for high-write workloads?
MongoDB excels at high-write throughput (e.g., logs, analytics). Optimize performance by indexing frequently queried fields, using bulk writes (`insertMany`, `updateMany`), and avoiding over-fetching. For >10K writes/sec, consider sharding or Atlas clusters.
How do I test MongoDB models in Laravel’s PHPUnit tests?
Use Laravel’s `DatabaseMigrations` or MongoDB’s `MockManager` to mock the database. For migrations, run `php artisan migrate:fresh` in tests. Example: `$this->actingAs($user)->get('/posts')->assertOk();` with a test database connection.
Are there alternatives to mongodb/laravel-mongodb for Laravel + MongoDB?
Other options include `jenssegers/laravel-mongodb` (older, less maintained) or building custom Eloquent extensions. However, `mongodb/laravel-mongodb` is the official, actively maintained choice with full Laravel 10.x+ support and MongoDB’s backing.
How do I verify the integrity of the package’s releases?
MongoDB signs release tags with their GPG key. Import the key (`gpg --import php-driver.asc`) and verify tags locally with `git show --show-signature <tag>`. While Composer doesn’t natively support this, it’s a manual safeguard against tampered releases.
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