How to organise a many to many relationship in MongoDB
Posted
by
Gareth Elms
on Stack Overflow
See other posts from Stack Overflow
or by Gareth Elms
Published on 2011-01-29T22:35:08Z
Indexed on
2011/01/29
23:26 UTC
Read the original article
Hit count: 189
I have two tables/collections; Users and Groups. A user can be a member of any number of groups and a user can also be an owner of any number of groups. In a relational database I'd probably have a third table called UserGroups with a UserID column, a GroupID column and an IsOwner column.
I'm using MongoDB and I'm sure there is a different approach for this kind of relationship in a document database. Should I embed the list of groups and groups-as-owner inside the Users table as two arrays of ObjectIDs? Should I also store the list of members and owners in the Groups table as two arrays, effectively mirroring the relationship causing a duplication of relationship information?
Or is a bridging UserGroups table a legitimate concept in document databases for many to many relationships?
Thanks
© Stack Overflow or respective owner