jenssegers/mongodb
This package brings MongoDB support to Laravel's Eloquent model and query builder, using the original Laravel API and methods so you can keep the same fluent syntax. Formerly jenssegers/mongodb, it is now mongodb/laravel-mongodb and supports Laravel 10.x as a drop-in replacement.
Architecture fit. This is an Eloquent-shaped abstraction over MongoDB, not a bolt-on driver. The package's stated design principle — "mirror Eloquent and the Laravel database layer so a model can move to MongoDB without rewriting code" — means the architectural decision is really a data-model decision, made per aggregate. Fit is strong where documents are the natural unit (event/log payloads, product catalogs with heterogeneous attributes, user profiles, CMS content, telemetry), and weak anywhere we depend on multi-table joins, rigid referential integrity, or long-running multi-statement transactions. The package also reaches beyond ORM: GridFS filesystem adapter (4.5), cache store (MongoStore), Scout search engine, and a batching driver (4.4), which creates an option to consolidate several infrastructure components onto one datastore — attractive for operational simplicity, but it also means a MongoDB outage becomes a broader blast radius than a single feature being down.
Integration feasibility. High for a Laravel 12+/PHP 8.2+ codebase. The 5.x line is an official MongoDB, Inc. project (transferred from jenssegers/mongodb), MIT-licensed, released on an automated, GPG-signed cadence through 5.9.1, with issues tracked in a public JIRA (PHPLARA) and a documented security-disclosure path. Eloquent API parity keeps the learning curve shallow for CRUD. The friction is concentrated in three places: (1) no schema migrations, so index and collection-shape management needs a bespoke deploy step; (2) embedded relationships (embedsMany/embedsOne) and hybrid relations behave differently from foreign-key relations under eager loading; (3) _id/id aliasing and ObjectId key types leak into route model binding, JSON contracts, and any code that assumes integer keys — a cross-cutting change, not a local one.
Technical risk. Medium overall, with three items I'd flag as decision-grade:
array cast that stores JSON-encoded strings is deprecated in favor of native BSON arrays. That is a silent, in-place data-shape migration, not a code change, and it needs a backfill plan.groupBy() producing an invalid $group stage when _id is selected, and 5.9.0 explicitly declines to support the base vector-search methods. Aggregation-builder bugs surface at runtime, and Atlas Vector Search is not covered by the ORM path — relevant if AI/retrieval features are on the roadmap.Note that "Dependents: 0" is a registry artifact, not a signal; download volume and seven-plus years of continuous releases point to broad production adoption. The low opportunity score (34.76) reflects a mature, crowded integration category with little greenfield value — which is exactly what we want in a dependency.
Key questions for engineering.
Stack fit. Fits the standard Laravel service topology cleanly: register a mongodb connection in config/database.php, add the service provider, and models extend the package's Eloquent base. Because the API mirrors Eloquent, existing repositories, policies, observers, and factories largely carry over — that is the package's core selling point and the reason integration effort lands in the data layer, not the application layer. Start with a single, low-blast-radius aggregate where document shape is genuinely variable; do not begin with the financial or transactional core.
Migration path. Two migrations, distinct and sequenced:
jenssegers/mongodb to mongodb/laravel-mongodb. 4.3.1+ includes a name fallback shim, but we should still update composer.json, config files, and any hardcoded class references explicitly rather than relying on the shim. Add a composer show assertion to CI to prevent the legacy name from reappearing.Compatibility. Confirm the framework/PHP/ext-mongodb matrix first, from the published compatibility tables rather than the README, and pin to a specific minor (5.9.x) rather than a floating constraint. If our baseline is Laravel 10 or 11, we must either stay on the 5.8.x line and accept a known support end, or upgrade the framework — a decision that should be made centrally, not by each team. Verify the ext-mongodb version installed in every environment, including CI.
Sequencing. (1) Topology and compatibility verification; (2) package swap and connection wiring in a non-production service; (3) index manifest and deploy tooling — build this before the first model, it is the item most likely to be skipped and most likely to cause an incident; (4) pilot aggregate with dual-write and shadow reads; (5) embed-relationship and cast-convention standards documented; (6) rollout of remaining contexts against that standard. Gate each context on an index review and a query-plan check before go-live.
Maintenance. Ongoing cost is dominated by two things: the version upgrade treadmill (a framework-version cliff has already occurred once in the 5.x line) and the absence of schema migrations. The latter shifts work from a one-time migration script to a permanent discipline — index creation, field-shape evolution, and backfills must live in a versioned, reviewed artifact. Budget explicit ownership for this; without it, indexes drift and performance degrades silently until an incident. Deprecation churn (e.g., the array-cast change) also implies periodic data backfills.
Support. MIT license, no procurement cost; official engineering is behind the MongoDB JIRA project and MongoDB's technical support channels. Community/OSS support is best-effort via JIRA and Stack Overflow — for anything revenue-critical, an enterprise MongoDB support agreement changes the escalation path substantially and should be priced into the decision alongside the datastore itself, not evaluated as a package concern.
Scaling. Horizontal scaling is MongoDB's strength, with caveats: unbounded embedded arrays are the classic failure — document growth toward the 16MB BSON limit, and embedsMany access patterns that force full-document rewrites on append. Set an explicit rule: embedded for bounded, read-together data; referenced for unbounded or independently-queried data. Eager loading semantics differ from belongsToMany/hasMany, so N+1 patterns will be new, not inherited, and need their own review checklist. Read scaling (secondary reads, Atlas tiering) is a datastore concern, but the ORM will happily emit collection scans if indexes are missing.
Failure modes. Prioritize detection for: (1) transactions failing on a standalone dev/topology mismatch — caught early, breaks loudly; (2) missing indexes producing collection scans — silent, degrades under load, the highest-probability incident; (3) document-size limit hits on embedded arrays — loud but only at scale; (4) invalid aggregation pipelines surfacing at runtime rather than review time; (5) stale or dropped connections in long-running queue workers (the package has fixed connection-closed exceptions before, so treat this as a recurring class, not a solved one); (6) cast/data-shape drift after a deprecation, producing wrong values quietly; (7) blast-radius expansion if GridFS, cache, and session stores are consolidated onto the same cluster.
Ramp-up. Eloquent fluency transfers almost entirely; MongoDB data modeling does not, and that is the actual onboarding cost. Plan a short, mandatory data-modeling session for every team touching the package — embedding vs. referencing, document growth, index design, and read/write concerns — plus a written convention doc. The package ships first-party developer-assistance assets (Laravel Boost skills and database-inspection tools), which measurably reduce time-to-first-working-model but also mean AI-generated queries will mirror whatever conventions we publish — so the convention doc is load-bearing, not decorative. Realistic ramp: a mid-level Laravel engineer is productive on CRUD in days; trustworthy on aggregation pipelines and index strategy in a few weeks, gated on review rather than tenure.
How can I help you explore Laravel packages today?