mongodb/laravel-mongodb · error · InvalidArgumentException
The "mongodb" batch driver requires a MongoDB connection…
Error message
The "mongodb" batch driver requires a MongoDB connection. The "%s" connection uses the "%s" driver.
What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/MongoDBBusServiceProvider.php:29 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mongodb/laravel-mongodb@0634653039 (2026-09-15).
Data as JSON: /api/errors/44baa2c97634f978.
Report an issue: GitHub.
Appendix: source
Thrown at src/MongoDBBusServiceProvider.php:29
use InvalidArgumentException;
use MongoDB\Laravel\Bus\MongoBatchRepository;
use Override;
use function sprintf;
class MongoDBBusServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register the service provider.
*/
#[Override]
public function register()
{
$this->app->singleton(MongoBatchRepository::class, function (Container $app) {
$connection = $app->make('db')->connection($app->config->get('queue.batching.database'));
if (! $connection instanceof Connection) {
throw new InvalidArgumentException(sprintf('The "mongodb" batch driver requires a MongoDB connection. The "%s" connection uses the "%s" driver.', $connection->getName(), $connection->getDriverName()));
}
return new MongoBatchRepository(
$app->make(BatchFactory::class),
$connection,
$app->config->get('queue.batching.collection', 'job_batches'),
);
});
/** The {@see BatchRepository} service is registered in {@see BusServiceProvider} */
$this->app->register(BusServiceProvider::class);
$this->app->extend(BatchRepository::class, function (BatchRepository $repository, Container $app) {
$driver = $app->config->get('queue.batching.driver');
return match ($driver) {
'mongodb' => $app->make(MongoBatchRepository::class),
default => $repository,
};View on GitHub (pinned to 0634653039)