0

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?

prasad_
  • 12,755
  • 2
  • 24
  • 36
Andrew
  • 55
  • 8

1 Answers1

0

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.

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • If I need to create databases for class, which I assume I will, shouldn't I instead be using `readWriteAnyDatabase`? Or is that a bad idea? Indeed, I don't really know what I'm doing. I'm not as familiar with Mongo as MySQL (even still not that familiar), so I might not be finding the right resources. – Andrew Aug 30 '21 at 01:27
  • For testing purposes on a development computer you do not need authentication at all. If your class requires specific permissions and users, do whatever the requirements are. – D. SM Aug 30 '21 at 04:34