Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB + Web App: Database per user

Tags:

mongodb

nosql

I'm in the process of evaluating MongoDB for a personal project. I'm putting together a site that will allow users to register and store information on my server.

While evaluating MongoDB I saw that it can create a database on the fly, the first time a record is inserted. That got me thinking that I could separate the data for each user into their own database. The database name will be derived from the user's unique id. After a user registers, the first time they store information their database will be created.

Does anyone know if this is a feasible design with MongoDB? Would it be better to simply store all user's data in a single database?

like image 448
Justin Kredible Avatar asked Dec 20 '11 22:12

Justin Kredible


People also ask

Is MongoDB good for user data?

NoSQL databases like MongoDB are a good choice when your data is document-centric and doesn't fit well into the schema of a relational database, when you need to accommodate massive scale, when you are rapidly prototyping, and a few other use cases.

How do I give a database access to a user in MongoDB?

MongoDB: db.grantRolesToUser() method is used to grants an additional role and its privileges to a user. The name of the user to whom to grant roles. An array of additional roles to grant to the user. The level of write concern for the modification.

Can you have multiple databases in MongoDB?

Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.

Can we use MongoDB for a web application?

MongoDB is general-purposeThe database can be used for several web applications, including customer data management, content management, data hubs, mobile apps, Internet of Things, Big Data, product and asset catalogs and database-as-a-service.


1 Answers

Yes, a single collection is better, that way you can use indexing to your advantage.

Iterating over a list of databases or collections will always take O(N) time whereas you could achieve O(log N) time to find individual documents using indexes.

like image 55
Tyler Brock Avatar answered Oct 11 '22 17:10

Tyler Brock