Create new user and grant it access to single database – MongoDB

Today we’ll create a new user and grant it access to a single database in MongoDB.

Start off by logging into mongodb with your admin/root user

You’ll land at a prompt like below if successfully authenticated

mongo terminal prompt

Issue the following to create a new user, replace the placeholders with your

The prompt will return with “Successfully added user” if successful

That’s it, try logging in using the new credentials:

To verify the credentials, issue the following to see how many databases show up

The prompt should return only one database followed by it’s size.