mongodb/laravel-mongodb
64.2
Adequate · 14 November 2026
13.3k
lines of production code
PHP
primary language
7
measurements over time
What this system is
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
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 CLI commands for managing Queryable Encryption collections and keys
Added three new Artisan commands to manage MongoDB Queryable Encryption: \mongodb:encryption:create-collection\ creates or recreates encrypted collections based on the \encryptedFieldsMap\ configuration (with \--dry-run\ and \--recreate\ options), \mongodb:encryption:rewrap-data-keys\ re-encrypts data keys under a new master key for a specified KMS provider, and \mongodb:encryption:status\ validates the encryption configuration and reports the state of mapped collections, including detecting mismatched or unencrypted collections.
src/Encryption/Commands · 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 MongoDB-specific database tools: DatabaseInfo and DatabaseQuery
Added two new MCP tools for MongoDB connections: \DatabaseInfo\ provides a summary of collections (names, types, estimated counts) and detailed information (indexes, options) for specific collections, and \DatabaseQuery\ executes read-only MQL commands (find, aggregate, count, distinct) against MongoDB. The \DatabaseQuery\ tool includes security measures to deny server-side JavaScript operators ($where, $function, $accumulator) and limits aggregation pipeline nesting and stages to prevent abuse.
src/Tools · 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
Queryable Encryption support for Laravel Eloquent models
This change introduces a new encryption subsystem in src/Encryption that enables MongoDB Queryable Encryption for Laravel applications. It adds configuration handling for auto-encryption options (including TLS settings and encrypted fields maps), automatic creation and validation of encrypted collections, and type coercion for encrypted fields to match their declared BSON types. The system also hides the reserved \_\safeContent\\_ field from hydrated models and reports mismatches between declared and stored encrypted fields, ensuring data integrity and compatibility with MongoDB's auto-encryption requirements.
src/Encryption · 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
Guidance for using Boost database tools with MongoDB connections
A new guideline document has been added to instruct users on how to handle Boost's database tools when the application uses MongoDB. It explains that standard tools like \database-schema\ and \database-query\ are designed for SQL databases and will not work with MongoDB connections. Users are advised to first check their database driver using the \database-connections\ tool, and if using MongoDB, to switch to the specific MongoDB equivalents: \database-info\ instead of \database-schema\, and \database-query-mongodb\ instead of \database-query\.
resources/boost/guidelines · high confidence
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 encryption status and collection creation commands; 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 cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 62 → 64 (+2.2)
- Rubric changed (rubric-2026.10.5 → rubric-2026.11.4) — scores are not directly comparable.
Lenses
- Code Health 60 → 59 (-0.4)
- Architecture 81 → 94 (+13.4)
- Maturity 59 → 66 (+6.9)
- Readiness 74 → 74 (+0.0)
- Security 64 → 64 (+0.0)
Resolved (4)
- Builder.toMql (cognitive 78) (src/Query/Builder.php)
- Builder.toMql (cyclomatic 39) (src/Query/Builder.php)
- Off-boarding risk: anonymized user #1
- Projects may be oversized for their cohesion
New (20)
- Builder.compileCommand (cognitive 78) (src/Query/Builder.php)
- Builder.compileCommand (cyclomatic 39) (src/Query/Builder.php)
- DocumentModel.setAttribute (cognitive 16) (src/Eloquent/DocumentModel.php)
- Duplicated block (13 lines × 2) (src/Query/Pipeline.php)
- Edited copies of one member (3 members, 17+ corresponding lines) (src/Eloquent/EmbedsRelations.php)
- Edited copy of a member (11 corresponding lines) (src/Eloquent/HybridRelations.php)
- Edited copy of a member (11 corresponding lines) (src/Eloquent/HybridRelations.php)
- Edited copy of a member (12 corresponding lines) (src/Helpers/QueriesRelationships.php)
- Edited copy of a member (13 corresponding lines) (src/Relations/HasOneThrough.php)
- Edited copy of a member (15 corresponding lines) (src/Query/Pipeline.php)
- Edited copy of a member (16 corresponding lines) (src/Eloquent/HybridRelations.php)
- Edited copy of a member (16 corresponding lines) (src/Query/Builder.php)
- Edited copy of a member (18 corresponding lines) (src/Relations/EmbedsMany.php)
- Edited copy of a member (20 corresponding lines) (src/Relations/EmbedsMany.php)
- Edited copy of a member (7 corresponding lines) (src/Encryption/EncryptedFieldTypes.php)
- Edited copy of a member (9 corresponding lines) (src/Helpers/QueriesRelationships.php)
- Off-boarding risk: anonymized user #1
- Orphaned file (src/Relations/EmbedsOne.php)
- TodoComment (src/Helpers/QueriesRelationships.php)
- TodoComment (src/Helpers/QueriesRelationships.php)
Changes since last survey
- 13 commits — 12 feature/other, 1 fixes
By area
- (repo) — 3 commits
- src/Query — 3 commits
- (root) — 2 commits
- resources/boost — 1 commit
- src/Eloquent — 1 commit
- src/Encryption — 1 commit
- src/Relations — 1 commit
- src/Schema — 1 commit
Notable commits
- fix: Fix Query\Builder::pluck() for distinct queries (#3667)
- change: Add AI Usage to CONTRIBUTING.md (#3661)
- change: Add Eloquent\Builder::getOrders()
- change: Merge 5.12 into 5.x (#3664)
- change: Merge 5.12 into 5.x (#3669)
- change: Merge 5.12 into 5.x (#3674)
- change: PHPLARA-283 Carry aggregation stages in the query pipeline (#3656)
- change: PHPLARA-287 Add BelongsToMany::newUnattachedQuery() (#3662)
- change: PHPLARA-326: Cache the encrypted field types per model instance (#3671)
- change: PHPLARA-328 Support whereHas() on embedded relations (#3673)
- change: Reduce the Queryable Encryption API on the Connection class (#3660)
- change: Reject out-of-range values in whereTime() (#3603)
- change: Treat a search index without a dynamic mapping as not dynamic in getIndexes() (#3668)
Written by cca.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 14 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 9ab770afd8c39b9f5bfd56084501324444e1cede — the exact code this score is about.
- Scored under rubric-2026.11.4 — the same rubric and the same method as every other entry in this index.
- Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.65+preprod-36d4cd83012f.