mongodb/laravel-mongodb
65.7
Adequate · 26 September 2026
9.6k
lines of production code
PHP
primary language
4
measurements over time
What this system is
This system is the \mongodb/laravel-mongodb\ package, a comprehensive driver that integrates MongoDB as a first-class database backend for Laravel applications. It provides full support for Eloquent ORM operations, including document modeling, hybrid relationships with SQL databases, and native aggregation pipelines, while extending Laravel's core infrastructure with MongoDB-backed implementations for caching, sessions, queues, and search indexing via Atlas Search. The library also includes specialized tooling for database introspection and agent skill validation, ensuring robust compatibility with modern Laravel versions and PHP standards.
How it got here
2013–2021 — MongoDB ownership migration and Laravel 12/13 support
13 changes.
This period covers the comprehensive modernization of the project following its transfer to MongoDB, Inc., including a major package rename and architectural overhaul to support Laravel 12 and 13. The work involved replacing legacy integration classes with a new Eloquent-based architecture, implementing native MongoDB features like Atlas Search and queue drivers, and establishing robust testing and CI/CD tooling.
2022–2024 — MongoDB feature expansion and test coverage
12 changes.
This period focused on expanding MongoDB integration by adding support for multi-document transactions, BSON type casts, and a batch repository for Laravel Bus. Significant effort was also dedicated to comprehensive test coverage across Eloquent, query builders, cache drivers, and static analysis to ensure stability and correctness of the new features.
2025–2026 — MongoDB integration and skill validation
8 changes.
This period focused on expanding MongoDB support within the Laravel ecosystem by introducing a dedicated Scout search engine, a custom session handler, and specialized diagnostic tools for non-SQL databases. Concurrently, the project enhanced its Agent Skills infrastructure by implementing comprehensive review, validation, and evaluation tooling to ensure quality and structural integrity before publication.
Features
Add MongoDB driver for Laravel Bus Batch repository
Introduces a new \MongoBatchRepository\ class that implements the \PrunableBatchRepository\ interface to store and manage Laravel Bus batches in MongoDB. This allows users to persist batch metadata (such as job counts, cancellation status, and timestamps) directly in a MongoDB collection, enabling batch processing features to work with MongoDB-backed job queues instead of requiring a relational database.
src/Bus · high confidence
Add MongoDB queue driver implementation
The src/Queue directory now includes a complete MongoDB-backed queue system consisting of MongoConnector, MongoQueue, and MongoJob classes. This allows users to configure Laravel's queue system to store and process jobs in a MongoDB collection instead of a relational database, with the connector handling configuration mapping (such as 'table' to 'collection' and 'expire' to 'retry\_after') and the queue implementation using atomic operations to reserve jobs and prevent race conditions.
src/Queue · high confidence
Add MongoDB-specific session handler
A new MongoDbSessionHandler class has been added to the src/Session directory, extending the standard Laravel DatabaseSessionHandler to store session data in MongoDB. This handler implements read, write, destroy, and garbage collection methods using MongoDB collections, and includes a createTTLIndex method to automatically expire old session documents.
src/Session · high confidence
Added MongoDB transaction management capabilities
The new \ManagesTransactions\ trait introduces support for MongoDB multi-document transactions. This enables users to execute atomic operations across multiple documents using standard transaction methods like \beginTransaction\, \commit\, and \rollBack\, as well as a convenience \transaction\ method that handles automatic retries and session management via the MongoDB driver's \with\_transaction\ utility.
src/Concerns · high confidence
Added MongoDB-specific database tools and usage guidelines
Boost now includes \database-info\ and \database-query-mongodb\ tools to support MongoDB Laravel connections, providing collection summaries, details, and read-only MQL execution as alternatives to the standard SQL-based \database-schema\ and \database-query\ tools. A new guideline document instructs users to verify their database driver and use these MongoDB-specific tools when the \mongodb\ driver is detected, ensuring compatibility and preventing errors with non-SQL databases.
resources/boost/guidelines, src/Tools · high confidence
Introduce MongoDB Scout engine for search indexing
Added a new \ScoutEngine\ implementation in \src/Scout/ScoutEngine.php\ that integrates Laravel Scout with MongoDB Atlas Search. This engine handles indexing, updating, and deleting searchable models by writing to a MongoDB collection configured with an Atlas Search index, supporting features like soft-delete metadata handling and bulk write operations.
src/Scout · high confidence
Introduce MongoDB-specific Query Builder, Grammar, and Aggregation components
This change introduces the core query-layer classes for the MongoDB driver: \Query\\Builder\ extends the Laravel base builder to support MongoDB operators, field aliasing (id to \_id), and vector search; \Query\\Grammar\ handles field preparation and result hydration, including arrow-to-dot notation conversion and DateTimeInterface to UTCDateTime transformation; and \Query\\AggregationBuilder\ provides a fluent interface for building and executing MongoDB aggregation pipelines with support for raw stages and lazy collections. These components replace the previous query implementation to provide native MongoDB query capabilities.
src/Query · high confidence
Introduce MongoDB-specific Schema Builder, Blueprint, and Grammar classes
The \src/Schema\ directory now contains new \Builder\, \Blueprint\, and \Grammar\ classes that extend Laravel's schema components to support MongoDB-specific operations. The \Builder\ provides methods like \hasColumn\, \hasCollection\, \getTables\, and \getViews\ to introspect MongoDB collections and views, while the \Blueprint\ class overrides standard index creation to use MongoDB's \createIndex\ and supports MongoDB-specific index options. These changes enable schema migrations and introspection to work correctly with MongoDB's document-oriented structure.
src/Schema · high confidence
MongoDB-specific Eloquent relationship implementations
The library now provides custom implementations for Eloquent relationships (BelongsTo, BelongsToMany, EmbedsMany, EmbedsOne, HasMany, HasOne, MorphMany, MorphOne, MorphTo, and MorphToMany) within the MongoDB namespace. These classes override standard Eloquent behavior to support MongoDB's document-oriented data model, including handling embedded documents, using MongoDB-specific query builders for constraints, and adapting sync/attach operations to work without traditional pivot tables.
src/Relations · high confidence
New Eloquent casts for MongoDB BSON types
Added four new Eloquent attribute casts to handle MongoDB-specific data types: \ObjectId\ (converts BSON ObjectIds to strings and vice versa), \BinaryUuid\ (handles UUID binary data), \AsBsonDocument\ (casts associative arrays to BSON documents), and \AsBsonArray\ (casts indexed arrays to BSON arrays). These classes allow developers to seamlessly integrate MongoDB's native BSON structures with Laravel's Eloquent ORM.
src/Eloquent/Casts · high confidence
New MongoDB Eloquent architecture with DocumentModel trait and hybrid relationships
The \src/Eloquent\ package has been restructured around a new \DocumentModel\ trait that serves as the core integration point for MongoDB models, replacing the previous \Model\ class inheritance. This trait provides MongoDB-specific behaviors including automatic \\_id\ to \id\ aliasing, UTCDateTime conversion, and support for Laravel 13 attributes via the \Table\ attribute. The update introduces \HybridRelations\ for cross-database relationships between SQL and MongoDB models, \EmbedsRelations\ for embedded document relationships, and a new \HasSchemaVersion\ trait for document versioning. The \Builder\ class now supports MongoDB Atlas features including \search()\ and \vectorSearch()\, while the \Auth/User\ class has been updated to use the new \DocumentModel\ trait. The legacy \SoftDeletes\ trait is deprecated in favor of Laravel's native implementation.
src/Eloquent · high confidence
New MongoDB integration components and service providers
This change introduces several new capabilities for Laravel applications using MongoDB: a new \CommandSubscriber\ class enables detailed query logging by capturing MongoDB driver events; a \MongoDBBusServiceProvider\ registers a \MongoBatchRepository\ to support Laravel's queue batching feature with MongoDB; and the \MongoDBServiceProvider\ is expanded to register a \ScoutEngine\ for MongoDB-based search indexing, a \GridFS\ adapter for the Flysystem filesystem, and Boost tools (\DatabaseInfo\ and \DatabaseQuery\) for database introspection.
src · high confidence
New skill review and validation tooling for Agent Skills
This change introduces a new \review-skill\ tool and a \validate-skills.sh\ script to help Subject Matter Experts (SMEs) validate and review Agent Skills before publishing. The \review-skill\ workflow guides users through structural validation using the \skill-validator\ CLI, content quality checks (covering clarity, actionability, token efficiency, scope discipline, directive precision, and novelty), and optional LLM-based scoring via the Claude CLI. It provides detailed interpretation frameworks and reporting assets to advise on necessary revisions. The accompanying \validate-skills.sh\ script allows for local, strict validation of skill directories, ensuring they meet structural requirements before submission.
tools · high confidence
Support for relationship aggregates and hybrid query constraints on document models
The library now supports aggregate functions (withCount, withExists, withSum, withAvg, withMin, withMax) on MongoDB document models. Because MongoDB lacks correlated subqueries, these aggregates are computed via additional queries after the parent documents are retrieved. Additionally, the Eloquent builder now handles hybrid queries (mixing MongoDB and relational databases) by using whereIn clauses instead of subqueries for relationship existence checks, enabling support for MorphToMany and other complex relations across different database connections.
src/Helpers · high confidence
Removals
Removal of legacy MongoDB integration classes
The legacy MongoDB integration classes—specifically \Connection\, \ConnectionResolver\, \Model\, \Query\, and \MongodbServiceProvider\—have been removed from the \src/Jenssegers/Mongodb\ directory. This change eliminates the old implementation that relied on the deprecated \MongoClient\ extension and the custom \Jenssegers\\Mongodb\\Model\ base class, indicating a migration to a newer MongoDB driver and Laravel database integration architecture.
src/Jenssegers · high confidence
Behavioural changes
MongoDB-aware validation presence checking
The validation layer now uses a MongoDB-specific presence verifier to correctly check for unique or existing values in MongoDB collections. Instead of relying on the default Laravel verifier, the system registers a custom \DatabasePresenceVerifier\ that uses case-insensitive regular expressions to match values, ensuring that partial matches (e.g., 'abc' matching 'abcd') are handled correctly. This change is wired up via a new \ValidationServiceProvider\ that overrides the default presence verifier registration.
src/Validation · high confidence
New optimized MongoDB cache and lock drivers with TTL auto-purge
The \src/Cache\ directory now introduces \MongoStore\ and \MongoLock\ as the primary cache and lock implementations, replacing previous versions. These new drivers support a serializable classes allowlist for safer unserialization, implement optimized atomic operations for cache and lock interactions, and automatically prune expired items via a lottery mechanism and a MongoDB TTL index on the \expires\_at\ field. The \MongoStore\ also fixes behavior for expired entries during increment operations and handles empty arrays/objects during deserialization.
src/Cache · high confidence
Repository modernization and documentation overhaul
The repository has been significantly modernized with the addition of development tooling including a Docker environment for testing, PHPStan static analysis configuration, PHP CS Fixer rules, and a Rector configuration for code modernization. The project has also adopted CycloneDX for Software Bill of Materials (SBOM) generation and updated its PHPUnit configuration to version 10.4. Documentation has been comprehensively rewritten to reflect the project's transfer of ownership to MongoDB, Inc., the new \mongodb/laravel-mongodb\ package name, and its compatibility with Laravel 10.x, while also adding release integrity verification instructions.
(repo-wide) · high confidence
Test coverage
Add test configuration files for database and queue connections; Added PHPStan static analysis tests for raw query methods and search index definitions; Added comprehensive test coverage for Query Builder, Grammar, and Aggregation Builder; Added comprehensive test coverage for model attribute casts; Added evaluation suite and syntax validation for Laravel MongoDB skill; Added test coverage for Eloquent Builder, Model attributes, and Aggregates; Added test coverage for MongoDB Laravel integration edge cases; Added test coverage for MongoDB cache store and lock mechanisms; Added test models for Laravel Scout integration; Added test models for MongoDB Laravel integration; Added test suite for Atlas Search index management and integration; Added tests for MongoDB batch repository; Added tests for new database diagnostic and query tools; Added unit and integration tests for the Scout search engine.
Dependencies
Major version upgrade to Laravel 12/13 and PHP 8.2+ with package rename
The \jenssegers/mongodb\ package has been renamed to \mongodb/laravel-mongodb\ and significantly updated to require PHP 8.2 or higher and the \ext-mongodb\ extension version 1.21 or 2. It now supports Laravel 12 and 13, replacing the previous Laravel 4.0 dependency with modern \illuminate/\*\ components (cache, container, database, events, support). The autoloading has migrated from PSR-0 to PSR-4 under the \MongoDB\\Laravel\ namespace, and the package now includes auto-discovery providers for the service bus. Development dependencies have also been updated to include PHPUnit 11/12, PHPStan, and Rector.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
This is the PUBLIC form of this artifact. Findings are listed in full, but the details of SECURITY findings — which rule fired, in which file, on which line, and how to fix it — are deliberately withheld, and any secret-scanner results are excluded entirely. Where detail is absent here it was REMOVED FOR PUBLICATION; it is not missing from the analysis. The complete artifact is available from the repository owner.
Score
- CAI 48 → 66 (+17.7)
- Rubric changed (rubric-2026.08.15 → rubric-2026.09.15) — scores are not directly comparable.
Lenses
- Code Health 96 → 92 (-4.1)
- Architecture 94 → 100 (+5.9)
- Maturity 57 → 56 (-1.8)
- Readiness 30 → 78 (+48.3)
- Security 55 → 64 (+9.2)
Resolved (43)
- Coverage not measured — test suite did not build
- Dimension evaluation failed
- Duplicated block (10 lines × 2) (src/Relations/MorphToMany.php)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- …and 23 more
New (90)
- Builder.compileWhereBasic (cognitive 19) (src/Query/Builder.php)
- Builder.compileWheres (cognitive 42) (src/Query/Builder.php)
- Builder.compileWheres (cyclomatic 23) (src/Query/Builder.php)
- Builder.toMql (cognitive 78) (src/Query/Builder.php)
- Builder.toMql (cyclomatic 39) (src/Query/Builder.php)
- ClassTooLong: Builder (src/Query/Builder.php)
- Dependency hygiene PARTLY measured — Composer dependencies read, no committed lock to grade for currency
- DocumentModel.addCastAttributesToArray (cognitive 25) (src/Eloquent/DocumentModel.php)
- DocumentModel.addCastAttributesToArray (cyclomatic 17) (src/Eloquent/DocumentModel.php)
- DocumentModel.originalIsEquivalent (cognitive 16) (src/Eloquent/DocumentModel.php)
- Documentation: no architecture or design documentation (README.md)
- Documentation: no installation or build instructions (README.md)
- Duplicated block (10 lines × 2) (src/Relations/BelongsToMany.php)
- Duplicated block (10 lines × 2) (src/Relations/BelongsToMany.php)
- Duplicated block (10 lines × 2) (src/Relations/EmbedsMany.php)
- Duplicated block (15 lines × 2) (src/Eloquent/EmbedsRelations.php)
- Duplicated block (15 lines × 2) (src/Relations/BelongsToMany.php)
- Duplicated block (17 lines × 2) (src/Relations/BelongsToMany.php)
- Duplicated block (8 lines × 2) (src/Relations/BelongsToMany.php)
- Duplicated block (9 lines × 2) (src/Eloquent/Casts/AsBsonArray.php)
- …and 70 more
Changes since last survey
- 22 commits — 17 feature/other, 5 fixes
By area
- (root) — 4 commits
- resources/boost — 3 commits
- src/Eloquent — 3 commits
- src/Relations — 3 commits
- (repo) — 2 commits
- src/Cache — 1 commit
- src/Query — 1 commit
- src/Schema — 1 commit
- tests/AtlasSearchIndexManagement.php — 1 commit
- tests/Bus — 1 commit
- tests/Models — 1 commit
- tests/TransactionTest.php — 1 commit
Notable commits
- fix: Fix .gitattributes to include skills (#3570)
- fix: Fix MongoBatchRepositoryTest bulk() mock for Laravel 13.33 named arguments (#3583)
- fix: Fix count method to handle null case (#3586)
- fix: PHPLARA-32 Fix attribute masked by a set-only Attribute mutator (#3557)
- fix: fix: morphOne() using the wrong MorphOne relation class (#3564)
- change: Add support for Laravel 13 attributes (#3565)
- change: Allow Laravel morphs by treating schema after as optional (#3569)
- change: Merge 5.11 into 5.x (#3585)
- change: Merge 5.11 into 5.x (#3588)
- change: Merge 5.9 into 5.x (#3574)
- change: PHPLARA-225 Support relation aggregates on document models (#3560)
- change: PHPLARA-249 support automated embedding in vectorSearch (#3556)
- change: PHPLARA-257 Replay query macros when eager loading MorphTo relations (#3559)
- change: PHPLARA-259 Add connection-level maxTimeMS defaults (#3571)
- change: PHPLARA-260 Force literal equality when a 3-arg where('=') has an operator array (#3581)
- change: PHPLARA-261 Compare cache lock owner values literally in $eq and $cond (#3579)
- change: PHPLARA-262 Support serializable classes allowlist in MongoStore cache (#3573)
- change: PHPLARA-264: verify resolved class is an Eloquent Model (#3589)
- change: PHPLARA-265 Reject a MongoDB operator as a scalar id or relation key (#3580)
- change: PHPLARA-266: Port skill improvements (#3576)
- …and 2 more
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
mongodb/laravel-mongodb was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 26 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 5fd872fc8a644c8139911121853d76219c5cc309 — the exact code this score is about.
- Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-a15879f6f801.