Best Pattern/Practice for multiple Meteor.Users 'assigned' to a single document using UserId?


Hi all!

I am looking for the best way to assign multiple Meteor.User accounts to a single doc, which from here we will call a “Group”. I would like to be able to assign just a userId so I only have to update their data in 1 spot. I am looking for patterns that would allow me to select who is in a group and what groups a user belongs.

I currently am approaching this in 2 ways. The 1st one I am assigning the user a role that would mean they are in a specific group. Then I also have an array of userIds and attempt some sort of $in query on that. The role part seems to be working great, but I am seeing alot of random errors when using $in. Though that might be cause I am using the latest Mongo (3.x?).


Well, I don’t know if I understood correctly what you’re trying to achieve but, if the “groups” you’re referring to are, in fact, user groups and roles, maybe you could try alanning:roles.

But if you’re referring to a N-N database relationship, why wouldn’t you just save the id of groups the user is in on his profile and the id of users in that group on the group entry on mongo? Take a look at this excellent Firebase doc entry for reference.


That is what I get for posting this before bed!

Here is how my app is setup… I have users which are normal account-pw / Meteor.Users. Then I have a db collection called Groups. If you think of a club in a school, it has about the same data structure… Name, type, meeting locations members, member levels (board members)… etc etc.

For quick and easy checking to see if a user is in a group I did use alanning:roles. This work great when doing Roles.userIsInRole(roleID) but for some reason I can’t get their reverse function, Roles.getUsersInRole, (which I know is expensive) to work! I am thinking I would go that way, but I can’t figure out how to get it to work.

Since I could not get that to work I added an array of Meteor.UserIds to the group doc called members and I have a not-so-Reliable $in query on Meteor.Users.

Thanks for taking the time to read and reply!