Summary
The MongoDB user with which you are creating the data source connection in Dremio must be able to read at least one collection in any database.
Reported Issue
After providing the correct master credentials for the MongoDB data source configuration, the source fails to save with an error message like: "Source '<data source name>' returned error 'Connection to Mongo failed. No collections were visible.'".
This error indicates that authentication was actually successful, but that no collections (datasets) are visible. The entry in the Dremio coordinator server logs looks similar to the following:
2025-01-30 06:43:25,581 [source-management23] INFO c.d.p.m.c.MongoConnectionManager - Created connection to [address=localhost:27017, user=dremio_mongo_user].
2025-01-30 06:43:25,582 [source-management23] INFO c.d.p.m.c.MongoConnectionManager - Number of open connections 1.
2025-01-30 06:43:25,582 [source-management23] INFO c.d.p.m.c.MongoConnectionManager - MongoClientOptions:
...
2025-01-30 06:43:25,662 [source-management23] INFO c.d.p.m.c.MongoConnectionManager - User Error Occurred [ErrorId: 8940e4a7-eed3-46f3-8902-4509e18631a8]
com.dremio.common.exceptions.UserException: Source 'LocalMongo' returned error 'Connection to Mongo failed. No collections were visible.'
at com.dremio.common.exceptions.UserException$Builder.build(UserException.java:984)
at com.dremio.plugins.mongo.connection.MongoConnectionManager.validateConnection(MongoConnectionManager.java:380)
at com.dremio.plugins.mongo.metadata.MongoSchemaFetcherImpl.getMongoVersionFromServer(MongoSchemaFetcherImpl.java:259)
at com.dremio.plugins.mongo.metadata.MongoSchemaFetcherImpl.getState(MongoSchemaFetcherImpl.java:107)
at com.dremio.plugins.mongo.MongoStoragePlugin.getState(MongoStoragePlugin.java:509)
at com.dremio.exec.catalog.ManagedStoragePlugin.lambda$initPlugin$22(ManagedStoragePlugin.java:1417)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Relevant Versions
All versions of Dremio.
Troubleshooting Steps
In MongoDB, find the user object you are trying to create the data source with and identify their "roles" property. This will be an array of "role" objects that indicate what entities, including databases, the user has access to.
Cause
Dremio needs to find at least one collection to create the data source. The MongoDB user you are trying to connect with must therefore have access to one or more collections in any database. Sometimes a user may be given their own authentication database in MongoDB for use with a client, like Dremio, but not assigned any read roles to other databases. This can cause the reported problem.
Steps to Resolve
Provide the MongoDB user read access to a database with some collections. Their authentication database does not necessarily have to contain a collection.