3 ms·
Use 2 collections (tables). Users - id - events_attended (array of event ids) Events - id - users_attended (array of user ids) If you want to get events
by weixiyen 16y ago
Use 2 collections (tables).
Users
- id
- events_attended (array of event ids)
Events
- id
- users_attended (array of user ids)
If you want to get events a user attended, do a query like:
1) get the user.events_attended array
2) events.find({_id:{$in: [user.events_attended] }})
3) now you have a nice json object of all events the user has been to
If you want to get all users that went to an event:
1) get the event.users_attended array
2) users.find({_id:{$in: [event.users_attended] }});
3) now you have a nice json object of all users who attended and event
- binomial 16y agoi.e. do it like you would in a relational database.