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

jenssegers/mongodb

View on GitHub
Deep Wiki
Context7

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Frequently asked questions about Mongodb
How do I install and configure `jenssegers/mongodb` for Laravel 11?
Run `composer require mongodb/laravel-mongodb` (updated package name), then configure the MongoDB connection in `config/database.php` under `connections`. Use the `mongodb` driver and specify your DSN or connection details. No additional service provider registration is needed in Laravel 11+.
Can I use MongoDB alongside PostgreSQL in the same Laravel app?
Yes, the package supports multiple database connections. Configure both `pgsql` and `mongodb` in `config/database.php`, then specify the connection in your Eloquent models using `protected $connection = 'mongodb'`. Polymorphic relationships can bridge the two.
Does this package support Laravel’s soft deletes? If not, what’s the workaround?
Soft deletes were deprecated in v5.x. Use MongoDB’s native `isDeleted` flag or implement a custom trait. Example: Add `$isDeleted = false` to your model and override `boot()` to handle soft delete logic manually.
Will complex Eloquent queries like `whereHas()` work with MongoDB?
Basic `whereHas` works, but nested relationships or subqueries may not translate cleanly. Test edge cases like `User::whereHas('posts', fn($q) => $q->where('views', '>', 1000))`—MongoDB lacks SQL-style joins, so denormalize data or use `$lookup` in aggregation pipelines.
What Laravel versions are officially supported, and how do I check compatibility?
The package officially supports Laravel 10–13.x (as of v5.7.0). For older versions (e.g., Laravel 8), use the `3.9` branch. Check the [release notes](https://github.com/mongodb/laravel-mongodb/releases) or run `composer why-not mongodb/laravel-mongodb` to verify conflicts.
How do I handle transactions with MongoDB in Laravel?
Use MongoDB’s multi-document ACID transactions via `$collection->getManager()->startSession()`. Wrap operations in a session and commit/cancel as needed. Avoid long-running transactions—design for short-lived atomic operations.
Are there performance differences between this package and native SQL queries?
CRUD operations are comparable, but aggregation queries may introduce latency due to MongoDB’s network overhead. Indexes (defined manually via `createIndex()`) are critical. Benchmark with tools like `tntsearch` or Laravel’s `DB::enableQueryLog()`.
Can I use MongoDB’s change streams or time-series collections with this package?
The package doesn’t natively support change streams or time-series collections. Use the [mongodb/mongodb PHP driver](https://www.mongodb.com/docs/drivers/php/) directly for these features, or extend the package via custom traits.
What are the alternatives to this package for Laravel + MongoDB?
Alternatives include `doctrine/mongodb-odm` (Doctrine’s ODM) or raw PHP driver usage. This package is preferred for Laravel teams due to its Eloquent compatibility, but Doctrine offers richer query capabilities for complex NoSQL use cases.
How do I migrate from SQL to MongoDB without breaking existing queries?
Start by denormalizing data (e.g., embed related records like `posts` in a `user` document). Replace foreign keys with MongoDB references or `$lookup` in aggregations. Test queries incrementally—complex Laravel queries (e.g., joins) may need manual rewrites.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony