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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -