具有多个客户端的Web应用程序数据库

具有多个客户端的Web应用程序数据库

问题描述:

在现实世界的Web应用程序中,如何为多个客户/公司/客户存储数据?

In a real-world web app, how does one go about storing data for multiple clients/companies/customers?

假设我们为一个客户拥有以下集合:

Lets assume we have the following collections for one client:

- users
- tasks

我如何将该系统扩展到第二个客户端?有没有标准的方法?

How would I extent this system to a second client? Is there a standard approach?

注意:我正在使用Firestore(无SQL).

Note: I am using Firestore (no-sql).

我们为每个客户端使用一组单独的集合.我们的数据结构对我们来说真的很好,看起来像这样……

We use a separate set of collections for each client. Our data structure works really well for us and looks like this...

/clients/{clientId}/reportingData
/clients/{clientId}/billingData
/clients/{clientId}/privateData

使用安全规则,我们允许客户读取其reportData和billingData集合,但不能读取privateData集合.

Using security rules, we allow clients to read their reportingData and billingData collections, but not the privateData collection.

但是,如果您需要同时在多个客户端之间查询数据(例如,供内部使用),那么Frank的选项1会更好,并带有clientId字段.

However, if you need to query data across multiple clients at the same time (for internal use, for example), then Frank's option 1 would work better, with a clientId field.

我们与用户做同样的事情...

We do the same thing with users...

/users/{uid}/publicProfile(任何人都可以阅读,只有用户可以写)

/users/{uid}/publicProfile (anyone can read this, only the user can write)

/users/{uid}/userProfile(仅用户可以读写)

/users/{uid}/privateProfile(用户无法读取或写入的内部数据)

/users/{uid}/privateProfile (internal data that the user can't read or write)