mongodb/laravel-mongodb · error · InvalidArgumentException
The database connection
Error message
The database connection "%s" does not use the "mongodb" driver.
What it means
Thrown while registering the 'gridfs' Flysystem disk when the connection named in the disk config (config['connection'] or similar) is not backed by the 'mongodb' driver. GridFS buckets can only live on MongoDB, so a mysql/pgsql/sqlite connection is rejected before the bucket is resolved; the error names the offending connection.
Solutions
- Point the gridfs disk config in config/filesystems.php at a connection whose driver is 'mongodb'.
- Verify the connection name spelled in the disk's 'connection' option exists in config/database.php and uses driver 'mongodb'.
- Add a dedicated MongoDB connection for GridFS storage and reference it.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/MongoDBServiceProvider.php:136 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/8a465f140222c269.
Report an issue: GitHub.
Appendix: source
Thrown at src/MongoDBServiceProvider.php:136
$this->app->resolving('filesystem', static function (FilesystemManager $filesystemManager) {
$filesystemManager->extend('gridfs', function (Application $app, array $config) {
if (! class_exists(GridFSAdapter::class)) {
throw new RuntimeException('GridFS adapter for Flysystem is missing. Try running "composer require league/flysystem-gridfs"');
}
$bucket = $config['bucket'] ?? null;
if ($bucket instanceof Closure) {
// Get the bucket from a factory function
$bucket = $bucket($app, $config);
} elseif (is_string($bucket) && $app->has($bucket)) {
// Get the bucket from a service
$bucket = $app->get($bucket);
} elseif (is_string($bucket) || $bucket === null) {
// Get the bucket from the database connection
$connection = $app['db']->connection($config['connection']);
if (! $connection instanceof Connection) {
throw new InvalidArgumentException(sprintf('The database connection "%s" does not use the "mongodb" driver.', $config['connection'] ?? $app['config']['database.default']));
}
$bucket = $connection->getClient()
->getDatabase($config['database'] ?? $connection->getDatabaseName())
->selectGridFSBucket(['bucketName' => $config['bucket'] ?? 'fs', 'disableMD5' => true]);
}
if (! $bucket instanceof Bucket) {
throw new InvalidArgumentException(sprintf('Unexpected value for GridFS "bucket" configuration. Expecting "%s". Got "%s"', Bucket::class, get_debug_type($bucket)));
}
$adapter = new GridFSAdapter($bucket, $config['prefix'] ?? '');
/** @see FilesystemManager::createFlysystem() */
if ($config['read-only'] ?? false) {
if (! class_exists(ReadOnlyFilesystemAdapter::class)) {
throw new RuntimeException('Read-only Adapter for Flysystem is missing. Try running "composer require league/flysystem-read-only"');
}View on GitHub (pinned to 0634653039)