0

I want to design a MongoDB schema where

  • There are multiple roles
  • There are multiple sites
  • users are mapped to sites with multiple roles like image below User Site Role Mapping

The DB Schema is as below for Permission

**permission**
id  
name
description

Role

**roles**
id
name
description
permission:[ids]

user

users
id
email
name
locationids:[ids]

unable to think through for

user_location_roles schema which will be easier to modify and easier to fetch from DB.

Please suggest schema that can be used

the UI for the site role user mapping is as below

enter image description here

rohit saraf
  • 37
  • 1
  • 8
  • 2
    I would do it exactly as you've drawn it. Looks good to me. Where is the difficulty? Build a method that selects location-based rights for a given user. – Jonathan Jul 29 '21 at 11:22
  • How the schema for user-location based rights should look like. The ui will look like the image added in the question – rohit saraf Jul 29 '21 at 12:34
  • 2
    Agreeing with @Jonathan, your schema makes sense to me. perhaps you just need an array of location-role tuples in the user object? like `permissions: [{location: "location1", role: "role1"}, {location: "location1", role: "role2"}, {location: "location2", role: "role2"}]` in your first picture – ray Jul 29 '21 at 13:03
  • That does depend on the specific use case. Are you needing Information based on the Location or based on the User? Is your Information restricted to the Location of the User? I think you are seeing problems here which aren't there. If it's about *authentication* I'd define a data schema for the rights and load them [the rights] in based on the Location and current User. – Jonathan Jul 29 '21 at 17:14
  • @Jonathan we will be needing the above info based on user for edit user page which will be same as add user and based on location for a user on location page. This schema is not used for authentication but for authorization – rohit saraf Jul 30 '21 at 06:35

0 Answers0