pul*_*hal 1 database-design datamodel firebase google-cloud-firestore
multi-tenant?作为专家,您认为这是为 Cloud Firestore 设计的不可能的数据模型吗?可以做到这一点的数据模型会是什么样子?
Ale*_*amo 15
As an expert, do you think this is an impossible datamodel to design for firestore?
Definitely is not impossible, actually is very simple.
What would a datamodel that can do this, look like?
A possible database schema for your use-case might be:
Firestore-root
|
--- users (collection)
| |
| --- uid (document)
| |
| --- organizations: ["organizationId", "organizationId"] (array)
| |
| --- //Other user properties
|
--- organizations (collection)
|
--- organizationId (document)
|
--- users: ["uid", "uid"] (array)
|
--- //Other organization properties
|
--- organizationData (collection)
|
--- organizationDataId (document)
|
--- //Organization Data properties
Run Code Online (Sandbox Code Playgroud)
Users can belong to an organization.
As you can see, the id of the user is added in users array which is a property within each organizationId document. Beeing an array, you can add all user ids of all users that are apart of that particular organization.
A user who signs up without any invitation from anyone, gets placed in their own organization (blah123) as its admin.
Once a user signs up, you create a new organization by generating a new organizationId and add user's in users array.
Multiple such users are founders of their own single organization in the same firestore based application. They can invite others and those invited join the founder's organization.
Answered above.
Any data created for the organization or any data created by the users of that organization should be segragated from the the users of another organization.
As you can see, I have created a subcollection named organizationData under organizationId document in which you can add as documents organization data. Because you already have the uid's of the user that are apart of this organization, you can simply use Firestore security rules to allow only those users to read that data.
如果需要,我们应该能够配置属于同一组织的用户以查看该组织的其他用户创建的任何数据。
在这种情况下,当用户加入一个组织时,您应该首先获取该组织的所有用户对象,然后查询数据库以获取这些用户所属的所有组织,并复制所有这些组织中的 uid。
就是这样 :)
| 归档时间: |
|
| 查看次数: |
1592 次 |
| 最近记录: |