{"record":{"id":"44baa2c97634f978","repo":"mongodb/laravel-mongodb","slug":"the-mongodb-batch-driver-requires-a-mongodb-connection-the-s","errorCode":null,"errorMessage":"The \"mongodb\" batch driver requires a MongoDB connection. The \"%s\" connection uses the \"%s\" driver.","messagePattern":"The \"mongodb\" batch driver requires a MongoDB connection\\. The \"(.+?)\" connection uses the \"(.+?)\" driver\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/MongoDBBusServiceProvider.php","lineNumber":29,"sourceCode":"use InvalidArgumentException;\nuse MongoDB\\Laravel\\Bus\\MongoBatchRepository;\nuse Override;\n\nuse function sprintf;\n\nclass MongoDBBusServiceProvider extends ServiceProvider implements DeferrableProvider\n{\n    /**\n     * Register the service provider.\n     */\n    #[Override]\n    public function register()\n    {\n        $this->app->singleton(MongoBatchRepository::class, function (Container $app) {\n            $connection = $app->make('db')->connection($app->config->get('queue.batching.database'));\n\n            if (! $connection instanceof Connection) {\n                throw new InvalidArgumentException(sprintf('The \"mongodb\" batch driver requires a MongoDB connection. The \"%s\" connection uses the \"%s\" driver.', $connection->getName(), $connection->getDriverName()));\n            }\n\n            return new MongoBatchRepository(\n                $app->make(BatchFactory::class),\n                $connection,\n                $app->config->get('queue.batching.collection', 'job_batches'),\n            );\n        });\n\n        /** The {@see BatchRepository} service is registered in {@see BusServiceProvider} */\n        $this->app->register(BusServiceProvider::class);\n        $this->app->extend(BatchRepository::class, function (BatchRepository $repository, Container $app) {\n            $driver = $app->config->get('queue.batching.driver');\n\n            return match ($driver) {\n                'mongodb' => $app->make(MongoBatchRepository::class),\n                default => $repository,\n            };","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/MongoDBBusServiceProvider.php#L11-L47","documentation":"Configuration guard in MongoDBBusServiceProvider::register. The queue batching repository (MongoBatchRepository) resolves the connection named by queue.batching.database; if that connection is not a MongoDB Connection (e.g. it uses the mysql or pgsql driver), the batch driver cannot store batch data in MongoDB, so registration fails with the resolved connection's name and driver reported.","triggerScenarios":"Thrown at src/MongoDBBusServiceProvider.php:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set queue.batching.database in config/queue.php to the name of a connection whose driver is 'mongodb' (config/database.php).","Create or repoint a MongoDB connection in config/database.php and use it for batching.","If batches are not needed, avoid using the mongodb queue/batch driver and keep the default database batching connection."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0634653039468ceb0268a69192bdac64469ed043","analyzedAt":"2026-09-15T02:56:37.067Z","contentChangedAt":"2026-09-15T02:56:37.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}