在MongoDB中对多租户数据库推荐的方法是什么? [英] What is the recommended approach towards multi-tenant databases in MongoDB?

查看:133
本文介绍了在MongoDB中对多租户数据库推荐的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用MongoDB创建一个多租户应用程序.关于我现在有多少个租户,我没有任何猜测,但是我希望能够扩展到成千上万.

I'm thinking of creating a multi-tenant app using MongoDB. I don't have any guesses in terms of how many tenants I'd have yet, but I would like to be able to scale into the thousands.

我可以想到三种策略:

  1. 同一集合中的所有租户,使用特定于租户的字段进行安全性
  2. 在单个共享数据库中每个租户有1个馆藏
  3. 每个租户1个数据库

我头脑中的声音暗示我选择了选项2.

The voice in my head is suggesting that I go with option 2.

思想和含义,有人吗?

推荐答案

我有相同的问题要解决,还要考虑变体. 由于我拥有多年创建SaaS多租户应用程序的经验,因此我还将根据我以前在关系数据库方面的经验来选择第二个选项.

I have the same problem to solve and also considering variants. As I have years of experience creating SaaS multi-tenant applicatios I also was going to select the second option based on my previous experience with the relational databases.

在进行研究时,我在mongodb支持网站上找到了这篇文章(由于不见了,所以回溯了): https://web .archive.org/web/20140812091703/http://support.mongohq.com/use-cases/multi-tenant.html

While making my research I found this article on mongodb support site (way back added since it's gone): https://web.archive.org/web/20140812091703/http://support.mongohq.com/use-cases/multi-tenant.html

这些家伙表示不惜一切代价避免使用第二种选择,据我了解,这并不是专门针对mongodb的.我的印象是,由于数据库设计的特殊性,这适用于我研究的大多数NoSQL数据库(CoachDB,Cassandra,CouchBase Server等).

The guys stated to avoid 2nd options at any cost, which as I understand is not particularly specific to mongodb. My impression is that this is applicable for most of the NoSQL dbs I researched (CoachDB, Cassandra, CouchBase Server, etc.) due to the specifics of the database design.

集合(或存储桶,或者它们在不同的数据库中称呼它)与RDBMS中的安全模式不同,尽管它们充当文档的容器,但它们对应用良好的租户分离毫无用处.我找不到可以基于集合应用安全限制的NoSQL数据库.

Collections (or buckets or however they call it in different DBs) are not the same thing as security schemas in RDBMS despite they behave as container for documents they are useless for applying good tenant separation. I couldn't find NoSQL database that can apply security restrictions based on collections.

当然,您可以使用基于mongodb角色的安全性来限制数据库/服务器级别的访问. ( http://docs.mongodb.org/manual/core/authorization/)

Of course you can use mongodb role based security to restrict the access on database/server level. (http://docs.mongodb.org/manual/core/authorization/)

在以下情况下,我建议使用第一种选择:

I would recommend 1st option when:

  • 您有足够的时间和资源来处理复杂的 设计,实施和测试此方案.
  • 如果您在结构和功能上不会有太大差异 数据库中针对不同租户的功能.
  • 您的应用程序设计将使租户仅能赚很少的钱 运行时进行自定义.
  • 如果要优化空间并最大程度地减少硬件的使用 资源.
  • 如果您要有成千上万的租户.
  • 如果您想以高成本快速扩展.
  • 如果您不打算基于租户备份数据(请分开保存) 每个租户的备份).即使在这种情况下,也有可能这样做 场景,但将付出巨大的努力.
  • You have enough time and resources to deal with the complexity of the design, implementation and testing of this scenario.
  • If you are not going to have much differences in structure and functionality in the database for different tenants.
  • Your application design will allow tenants to make only minimal customizations at runtime.
  • If you want to optimize space and minimize usage of hardware resources.
  • If you are going to have thousands of tenants.
  • If you want to scale out fast and at good cost.
  • If you are NOT going to backup data based on tenants (keep separate backups for each tenant). It is possible to do that even in this scenario but the effort will be huge.

如果满足以下条件,我会选择变体3:

I would go for variant 3 if:

  • 您将拥有一小部分租户(数百名).
  • 具体业务要求您能够支持不同租户的数据库结构上的巨大差异(例如,与第三方系统的集成,数据的导入和导出).
  • 您的应用程序设计将允许客户(租户)在应用程序运行时进行重大更改(添加模块,自定义字段等).
  • 如果您有足够的资源来快速扩展新的硬件节点.
  • 如果要求您保留每个租户的数据版本/备份.恢复也很容易.
  • 存在法律/法规限制,迫使您将不同的租户保留在不同的数据库(甚至是数据中心)中.
  • 如果您想充分利用mongodb的即用型安全功能(例如角色).
  • 租户之间在大小问题上有很大的差异(您有很多小租户,很少有非常大的租户).

如果您发布有关您的应用程序的其他详细信息,也许我可以为您提供更详细的建议.

If you post additional details about your application, perhaps I can give you more detailed advice.

这篇关于在MongoDB中对多租户数据库推荐的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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