In MongoDB, can I add a regular user that can read any non-admin DB?

216 Views Asked by At

I have MongoDB set up on my laptop for a MEAN Stack university class I'm taking this semester, but of course I don't know what databases I'll be creating for the class, nor how many.

I found this SO question about adding users to MongoDB, and I have a regular user for myself for non-admin stuff. From what I can see in the answer to that question, and from this page of the Mongo documentation, it is not possible to create a user that can read a database that is to be created in the future. Is this indeed the case, or is there some hard-to-find way around it?

1

There are 1 best solutions below

2
On

The permissions do not need to reference existing databases. For a role that has read access to most databases, see https://docs.mongodb.com/manual/reference/built-in-roles/#mongodb-authrole-readAnyDatabase.

You may be confused with the concept of auth source/authentication database in MongoDB. Users may be defined in the admin database which bypasses the issue of them referencing databases that don't exist yet.