Say I have a user who can belong to multiple roles within a group. It is modeled like this (from third party library).
假设我有一个可以属于组内多个角色的用户。它是这样建模的(来自第三方库)。
{
_id: '1',
roles: {
'repo1': ['contributor'],
'repo2': ['contributor', 'moderator', 'reviewer']
}
}
For each role type, there is a different profile type. For example, a reviewer
might have a schema like so:
对于每种角色类型,都有不同的配置文件类型。例如,审阅者可能具有如下架构:
{
approved: [{
pullRequest: '5678',
message: 'Now can manage 3D integration',
when: ISODate()
}],
denied: [{
pullRequest: '1234',
reason: 'Failed tests',
when: ISODate()
}]
}
which might be different than a contributor
's profile. Users can still have a profile in every group for every role they are in.
这可能与贡献者的个人资料不同。对于他们所处的每个角色,用户仍然可以在每个组中拥有一个配置文件。
In NoSQL, how do you manage multiple types of user profiles? What is the most correct type of schema and relationship for this application?
在NoSQL中,您如何管理多种类型的用户配置文件?此应用程序的最正确的架构和关系类型是什么?
1 个解决方案
#1
0
In your example, I assume a reviewer is approving and denying pullRequests. This is information you would not want to store on a user's document, but instead offset to a new collection you would probably call PullRequests. Each document in the PullRequests collection would represent a single PullRequest and you would store information regarding that particular PullRequest on that document, including if it was approved/denied and subsequently who approved/denied it and for what reason. Storing the role on the user document is for validation purposes so that you can check to see if someone has the required permissions; logging information regarding their activity is best left to a separate Collection. It's a clear separation of concerns and this model relationship will be easier to maintain.
在您的示例中,我假设审阅者正在批准并拒绝pullRequests。这是您不希望存储在用户文档中的信息,而是偏移到新集合,您可能会调用PullRequests。 PullRequests集合中的每个文档都代表一个PullRequest,您可以在该文档中存储有关该特定PullRequest的信息,包括它是否被批准/拒绝以及随后谁批准/拒绝它以及出于什么原因。在用户文档上存储角色是出于验证目的,以便您可以检查某人是否具有所需权限;有关其活动的记录信息最好留给单独的集合。这是一个明确的关注点分离,这种模型关系将更容易维护。
Feel free to ask any follow ups.
随意询问任何后续行动。
#1
0
In your example, I assume a reviewer is approving and denying pullRequests. This is information you would not want to store on a user's document, but instead offset to a new collection you would probably call PullRequests. Each document in the PullRequests collection would represent a single PullRequest and you would store information regarding that particular PullRequest on that document, including if it was approved/denied and subsequently who approved/denied it and for what reason. Storing the role on the user document is for validation purposes so that you can check to see if someone has the required permissions; logging information regarding their activity is best left to a separate Collection. It's a clear separation of concerns and this model relationship will be easier to maintain.
在您的示例中,我假设审阅者正在批准并拒绝pullRequests。这是您不希望存储在用户文档中的信息,而是偏移到新集合,您可能会调用PullRequests。 PullRequests集合中的每个文档都代表一个PullRequest,您可以在该文档中存储有关该特定PullRequest的信息,包括它是否被批准/拒绝以及随后谁批准/拒绝它以及出于什么原因。在用户文档上存储角色是出于验证目的,以便您可以检查某人是否具有所需权限;有关其活动的记录信息最好留给单独的集合。这是一个明确的关注点分离,这种模型关系将更容易维护。
Feel free to ask any follow ups.
随意询问任何后续行动。