How to model sql break entity?

Hello, so I worked with mysql and I had 3 tables as in the attachment, the table in middle is like breaking between the other two, which allows me as a user to have the same card multiple times, as in a card collection games, you can have the same card many times but each card has it’s own record. How can I model this scenario in mongo DB? thx

Hi @David_Garcia2 ,

So in MongoDB there are several ways to model this data and how exactly should you do that depands on your query pattern and the needed data in your application modules.

If cards are shared among users but each user has a limited amount of cards it sounds like having a users collection and a cards collection make sense where “users cards” are embedded in user as an array in form of an extended pattern:

// Users 
{ _id : ...,
 Username : ... ,
  UsersCards: [ { cardId : ... , <Additional needed  fields>},  { cardId : ... , <Additional needed  fields>} ...]

// Cards 
{ _id : ... , 
  CardName : ... , 

So every time a user get a card from the cards deck it is pushed into his own cards, and pulled when he needs to remove it…


Hi Pavel, thanks for the reply, so according to your reply, inside the users collection I can have the same card id many times, representing that I have that card repeated many times (as in a card collector game), is that correct?

@David_Garcia2 , exactly.