MongoDB + Web App: Database per user

拟墨画扇 提交于 2019-12-10 12:55:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8582683/mongodb-web-app-database-per-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!