0

I'm a MongoDB beginner previously MySQL user. I was wondering what the correct way is to store and update data that relates to one another in MongoDB.

Say I have 2 entities User and Item. Everytime I display an item, i want to show all user information together with it, so I copy the user information into my Item object when creating an Item:

Item
------
itemID
itemName
userName
userID
userLocation

Say I update the userName of the user related to that item. That means I need to target all the Items that has the userID to update the userName of those Items. Is that the right way of doing it? Or would you reference the user inside the Item Object like this?

Item
------
itemID
itemName
userID

and perform a specific query? What's the MongoDB way of storing data and updating it?

So far I've just been doing this "Bulk" update kind of way doing it but I'm not sure what's the best practice in this case.

jones
  • 585
  • 3
  • 10
  • 30

0 Answers0