Say I wan’t to check if a user belongs to a group, to check if it has permission to access content.
I can either do:
GroupUsersCollection example documents:
A) {_id, userIds:['eu4jg94jbmt84', '493jgnrkejs']}
B) {_id, _eu4jg94jbmt84:1, _493jgnrkejs:1}
In the second example, the users are fields in the object (prefixing with underscore as user ids can start with a number).
The second example is also good for subscriptions, I believe, as any change in the “userIds” array of example ‘A’ would send to the client the entire modified array.
Also, I’ve read that object key lookup is faster than indexOf/includes.
So, what do you think?
Is there a better way?