javascript - How to create user roles and permission in mongodb / nosql -
ive been searching while trying find tutorials on how make typical website mvc permission system using user roles.
ive done such things using sql , relations, in nosql databases, done differently ( assume).
what have in mind this
//role objects {roles : [ { '_id' : 'uniqueid', 'role_name' : 'admin', 'permissions_granted' : [array of permission strings] }, { '_id' : 'uniqueid', 'role_name' : 'user', 'permissions_granted' : [array of permission strings] }, { '_id' : 'uniqueid', 'role_name' : 'guest', 'permissions_granted' : [array of permission strings] } ]} //user objects {users: [ { '_id' : 'uniqueid', 'username' : 'mike', 'password' : 'mypass', 'permissions' : [an instance of role group, or id ? ] }, { '_id' : 'uniqueid', 'username' : 'jonny', 'password' : '123', 'permissions' : [???] } ]} how make single query fetches user data + permissions ? there downside of using 2 querys, 1 user's role id, , permissions roles document. ? how user permissions handled in nosql databases mongodb
you should use ids , not objects such. way can update easily. if have scenario, when read permissions , write seldom (which assume) can store additionally role id's actual permissions of user (based on roles)
however need update permissions, every time role updated. when querying user roles it, faster 2 separate queries.
Comments
Post a Comment