'When should we use embedded documents in MongoDB?
I read a lot about embedding in MongoDB, but still I don't know when to use it. I thought of some scenarios:
I have A collection named UserGroups with these fields:
- _id
- name
Now I want to add an user to Users collection:
I should have a groupName field in Users collection and update it when UserGroups collection gets an update.
I should add the groupId field in Users collection and perform a join whenever I want the UserGroups.name.
I should add the user document as an embedded document to UserGroups collection.
Or I should add the userGroup document as an embedded document in Users collection. though, I don't think I should do it.
Which option should I use?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
