MongoDB + Web App:每个用户的数据库 [英] MongoDB + Web App: Database per user

查看:95
本文介绍了MongoDB + Web App:每个用户的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估针对个人项目的MongoDB.我正在组建一个站点,该站点将允许用户在我的服务器上注册和存储信息.

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.

在评估MongoDB时,我看到它可以在首次插入记录时动态创建数据库.那使我想到可以将每个用户的数据分离到他们自己的数据库中.数据库名称将从用户的唯一ID派生.用户注册后,将在他们第一次存储信息时创建其数据库.

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.

有人知道这对MongoDB是否可行?将所有用户数据简单地存储在一个数据库中会更好吗?

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?

推荐答案

是的,单个集合更好,这样您就可以利用索引来发挥自己的优势.

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

遍历数据库或集合列表将始终花费O(N)时间,而使用索引来查找单个文档则可以花费O(log N)时间.

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.

这篇关于MongoDB + Web App:每个用户的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆