Relationships and References in Mongo DB

I am currently working on a project that has many threads that users can create. The user has different permissions for streams, which can be specified by users with administrator rights. A user must be added to a stream before they can access it.

When a user is added to a stream, they are granted read, write, or admin permission. Users can also be part of groups. These groups can then be added to the stream, in which case all users in the group will be added along with the permission specified for the group.

thread: {id: xxxxx, users:[{id:user01, permission: write, discovery: non}, {id:user02, permission: read, discovery: GroupA}]}

      

Thus, a user can be added with individual permission, or can be added with permission granted to the group they belong to. Discovery will determine if the user was added individually or as a group.

I'm wondering if this would be the best way to set up Mongo for such a permission system, and also how do I actually define this schema using Mongoose? I think it would be fastest to include all these aspects in every thread.

+3


source to share





All Articles