简体   繁体   English

将 MongoDB Atlas 数据划分为 Realms

[英]Partitioning MongoDB Atlas Data into Realms

I am working through partitioning of MongoDB Atlas data into Realms to use the Realm sync feature for mobile devices.我正在将 MongoDB Atlas 数据分区到 Realms 中,以便为移动设备使用 Realm 同步功能。 For reference, I am looking at the information provided here:作为参考,我正在查看此处提供的信息:

https://docs.mongodb.com/realm/sync/partitioning/#partitioning https://docs.mongodb.com/realm/sync/partitioning/#partitioning

When sharing data between users, MongoDB proposes the following partition strategy:在用户之间共享数据时,MongoDB提出如下分区策略:

User Realms: If your application stores data privately for each individual user, you could create an owner_id field containing a specific user ID for every document.用户领域:如果您的应用程序为每个用户单独存储数据,您可以为每个文档创建一个包含特定用户 ID 的 owner_id 字段。 Selecting the owner_id field as your partition key would partition your database into realms corresponding to individual users.选择 owner_id 字段作为您的分区键会将您的数据库分区为与各个用户对应的领域。

Team Realms: If your application shares resources across teams, you could create a teams collection that maps user IDs to team IDs.团队领域:如果您的应用程序跨团队共享资源,您可以创建一个将用户 ID 映射到团队 ID 的团队集合。 You could then create a team_id field containing a specific team ID for every document you want to sync.然后,您可以为要同步的每个文档创建一个包含特定团队 ID 的 team_id 字段。 Selecting the team_id field as your partition key would partition your database into realms containing data for entire teams.选择 team_id 字段作为您的分区键会将您的数据库分区为包含整个团队数据的领域。

Public Realms: It's often helpful to store read-only data viewable to all users;公共领域:存储所有用户都可以查看的只读数据通常很有帮助; for this kind of use case, you can define a special partition value in your permissions, such as PUBLIC, that all users sync with read permissions only.对于这种用例,您可以在您的权限中定义一个特殊的分区值,例如 PUBLIC,所有用户仅使用读取权限同步。

So that all makes sense, but what about documents that a user creates and then shares with one or more other users?所以这一切都说得通,但是用户创建然后与一个或多个其他用户共享的文档呢? If I have a sharedWith field that points to other user_id's , and I make that the partition key, then it could work but all the documentation seems to caution against updating the value of these partition keys for risk of triggering a client reset.如果我有一个指向其他user_id's sharedWith字段,并且我将它设为分区键,那么它可以工作,但所有文档似乎都警告不要更新这些分区键的值,以免触发客户端重置的风险。

Through the research I've done via google, StackOverflow etc., I can only find examples that assume the data stays static but I need to allow users to add and remove the sharing permissions.通过我通过 google、StackOverflow 等进行的研究,我只能找到假设数据保持静态的示例,但我需要允许用户添加和删除共享权限。 Any suggestions on how this might be approached?关于如何解决这个问题的任何建议?

I don't use Realm but looking at that documentation I'd say for documents you would use the public partitioning with document id as the prefix, similarly to how salespeople are handled.我不使用 Realm,但查看该文档我会说对于文档,您将使用以文档 ID 作为前缀的公共分区,类似于销售人员的处理方式。

Then I imagine you'd need to have a server-side endpoint for sharing which would write permitted document ids into all of the users that have access to those documents (the server-side endpoint will be able to see the complete view of data, not limited to any one user).然后我想你需要有一个服务器端共享端点,它将允许的文档 ID 写入所有有权访问这些文档的用户(服务器端端点将能够看到完整的数据视图,不限于任何一个用户)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM