Search code examples
mongodbauthenticationdatabase-security

MongoDB Dynamic Database


Good day. I am starting a web project and am thinking about using mongoDB with Java and Spring data. In this web project each user would have a database. Other words, when the user signs in (this would be a shared database where only contain login information), i would have used the database given user. Is this possible? What is the most elegant way to implement? Follow the example of this link, which uses spring date with mongodb.


Solution

  • Using the databases auth layer within the application is normally a bad idea, you don't want your application to be able touch something that sensitive.

    As for using separate databases: if your work flow really calls for it then you would want to go separate databases, not collections. This for sharding reasons (sharding is per database) and lock reasons (lock is still database level), also a lot of other things sit on database level.

    It should be noted that unless you need the isolation then one user per database is a very bad idea, not only due to cost efficiency but also due to application complications that will need to be taken into consideration.