- What is jenssegers/mongodb and is it still maintained?
- jenssegers/mongodb is the original Composer name for a package that adds MongoDB support to Laravel's Eloquent models and query builder. It has been renamed to mongodb/laravel-mongodb after ownership transferred to MongoDB, Inc., and it is now maintained by MongoDB. New projects should require mongodb/laravel-mongodb rather than the old package name.
- How do I install mongodb/laravel-mongodb in a Laravel application?
- Install it with Composer using composer require mongodb/laravel-mongodb, and make sure the mongodb/mongodb PHP driver is available; v5.x requires driver version 2.0.0 or newer. Then add a MongoDB connection in config/database.php using MongoDB\Laravel\Connection and have your models extend MongoDB\Laravel\Eloquent\Model. The package is distributed as mongodb/laravel-mongodb, not the older jenssegers/mongodb name.
- Which Laravel versions are compatible with mongodb/laravel-mongodb?
- The current package documentation states compatibility with Laravel 10.x, and current releases also cover newer Laravel versions such as 11.x through 13.x according to the package notes. For older Laravel versions you need to use the legacy 3.9 branch. Always check the release notes before upgrading because minor releases can include behavior changes.
- Can I use Eloquent models and relationships with MongoDB in Laravel?
- Yes. The package extends Laravel's Eloquent model and query builder so you can keep using familiar methods such as where, orWhere, with, and relationships. MongoDB-specific features such as aggregation pipelines, geospatial queries, $lookup, and $facet are also available. Just extend MongoDB\Laravel\Eloquent\Model and use the MongoDB connection.
- How do I migrate an existing Laravel SQL application to MongoDB?
- Replace the SQL connection in config/database.php with a MongoDB connection using MongoDB\Laravel\Connection, and change models from Illuminate\Database\Eloquent\Model to MongoDB\Laravel\Eloquent\Model. You will also need to review migrations, indexes, relationships, and any SQL-specific queries because MongoDB does not use native joins and has different transactional behavior. Plan the move carefully rather than treating it as a drop-in connection swap.
- Do I need migrations if MongoDB is schema-less?
- MongoDB does not require rigid table-style migrations, which is a good fit for evolving or nested document structures. However, you should still create collections and indexes deliberately, for example with Schema::create and createIndex in Laravel migrations, especially for frequently queried fields like _id or email. Treat indexes and data-shape conventions as part of your deployment process.
- Does laravel-mongodb support MongoDB transactions?
- Yes, multi-document transactions are supported, but they require a MongoDB version that supports them; older MongoDB versions lacked ACID transactions, while MongoDB 5.0 and later provide them. The package includes a TransactionManager and you should add retry logic for transient transaction failures. Transactions are not a substitute for good schema and index design.
- What are common performance pitfalls with MongoDB and Laravel Eloquent?
- Missing indexes on frequently queried fields are a major cause of slow queries, so create indexes for fields such as _id and email. Eager loading with with() is supported, but deeply nested data and N+1 query patterns may need manual optimization. MongoDB query logs are less intuitive than SQL EXPLAIN output, so use the package's Debugger or $explain() to analyze queries.
- Is laravel-mongodb 5.11.0 a security release I must apply?
- Yes. Version 5.11.0 is a security release that closes four CVEs and hardens the cache store, making it a must-patch for internet-facing deployments. It changes query construction so operator arrays passed through three-argument where('field', '=', ...) and operator values used as scalar IDs or relation keys are coerced to literal values. If your application intentionally passed MongoDB operators through those paths, audit and update it before upgrading.
- When should I avoid using MongoDB with Laravel?
- Avoid MongoDB when your application is highly transactional, such as banking-style systems, or when it depends heavily on complex SQL joins and strict relational constraints. MongoDB is a better fit for content management, real-time analytics, JSON APIs, IoT telemetry, and hierarchical or nested data. If your workload is mostly relational reporting and ACID-heavy operations, a relational database is usually the safer choice.