英文:
What would be a good mongodb schema for a web app with multiple permission types?
问题
我正在开发一个Web应用程序(ASP.NET Core 6),用户可以访问各种工作环境,在这些环境中,他们可以访问多个工作空间。
关于工作环境,用户可以是“管理员”或“工作者”。这决定了用户是否能够在该环境内创建工作空间。
另一方面,工作空间可以是“公共”或“私有”。公共工作空间可以被该环境内的任何用户访问,而私有工作空间只能被由创建该工作空间的管理员授权的用户访问。
我发现在这方面定义数据库模式很困难。我考虑创建2个集合来定义用户和工作空间/工作环境之间的关系(UserId
和 WorkspaceId
或 EnvironmentId
),但我不确定是否将其分开是正确的方法,因为工作空间的访问也取决于它们所在的工作环境的访问权限。
顺便说一下,这是我第一次使用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
内进行过滤等更多操作。
我创建了一个示例,演示了如何处理类似你的示例数据(UserId
和WorkspaceId
或EnvironmentId
)。
英文:
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
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论