对于具有多种权限类型的Web应用,一个良好的MongoDB模式可能如下所示:

huangapple go评论69阅读模式
英文:

What would be a good mongodb schema for a web app with multiple permission types?

问题

我正在开发一个Web应用程序(ASP.NET Core 6),用户可以访问各种工作环境,在这些环境中,他们可以访问多个工作空间。

关于工作环境,用户可以是“管理员”或“工作者”。这决定了用户是否能够在该环境内创建工作空间。

另一方面,工作空间可以是“公共”或“私有”。公共工作空间可以被该环境内的任何用户访问,而私有工作空间只能被由创建该工作空间的管理员授权的用户访问。

我发现在这方面定义数据库模式很困难。我考虑创建2个集合来定义用户和工作空间/工作环境之间的关系(UserIdWorkspaceIdEnvironmentId),但我不确定是否将其分开是正确的方法,因为工作空间的访问也取决于它们所在的工作环境的访问权限。

顺便说一下,这是我第一次使用MongoDB,所以也许我还不太了解这里的关系是如何工作的。

英文:

I'm developing a web app (ASP.NET Core 6) where a user can have access to various work environments, and within those environments, they can have access to multiple workspaces.

Regarding the work environments, a user can be "Admin" or "Worker". This determines whether or not the user will be able to create workspaces within that environment.

On the other hand, the workspaces can be "Public" or "Private". Public ones can be accessed by any user inside that environment, while private ones can only be accessed by authorized users set by the Admin who created said workspace.

I'm finding it hard to define the database scheme in this matter. I was thinking about creating 2 collections to define relations between user and workspace/work environment (UserId and WorkspaceId or EnvironmentId), but I'm not sure if separating it like this is the right approach since workspaces access depends on their work environment access as well.

BTW, this is my first time using MongoDB so maybe I'm not quite understanding how relations work here.

答案1

得分: 1

我以前从未使用过ASP.NET,但你可以通过执行聚合查询的lookup来连接两个或更多的集合。
参考: $lookup (aggregation)

你还可以在$lookup内进行过滤等更多操作。

我创建了一个示例,演示了如何处理类似你的示例数据(UserIdWorkspaceIdEnvironmentId)。

MONGO PLAYGROUND

英文:

i never use ASP.NET before, but you can join 2 or more collections by perform lookup with query agregation .
reff: $lookup (aggregation)

you can also filtering within the $lookup and much more.

i create an example how to approach like the your sample data (UserId and WorkspaceId or EnvironmentId)

MONGO PLAYGROUND

huangapple
  • 本文由 发表于 2023年2月27日 03:31:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574527.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定