0

I want to implement database authentication in mongodb.

In order to do that, I found out that I need to first create an admin user and then create separate users for each of my database through mongodb client shell (manually or using a javascript file).

I was wondering if it is possible to add user to the individual databases from the spring application itself but did not get any useful pointers to do this. Is it that this approach is wrong because if this possible the application will always be able to access the database because it itself is creating the user, but external access will still be blocked.

Please let me know how this can be achieved or if it is an incorrect approach.

1 Answer 1

1

After you add a normal user via the MongoShell, you can then connect via your application and create either normal users, or read only users.

Note that a normal user can also add users, so the users your application adds may need to be down as read only users depending on your use case and needs.

In the MongoShell, adding a read only user can be done via

use myAppDB
db.addUser("JohnSmith", "CheddarCheese", true)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.