I'm building an app where a user object has multiple game objects. What would be the proper strategy for fetching all of a user's games from a mongoDB database?As far as I can tell I have 2 options:1: One option is to give users a game property that is an array of ids of games that the user has and then fetch each game individuallye.g.example user{ _id: '1342', name: 'Dave', games: [ '12345678', 'fgnhe45rnd', ], }example game{ _id: '12345678', name: 'Fluxx', }2: The opposite. Give each game a users property that is an array of ids of users that own that game. Then fetch all games that have a specific user's id.e.g. example user{ _id: '1342', name: 'Dave', }example game{ _id: '12345678', name: 'Fluxx', users: [ '1342', '5783', ], }Any advice is appreciated. Thank you.
Submitted March 31, 2018 at 05:03PM by yonatanmk
No comments:
Post a Comment