We are adopting MongoDB for a new solution and are currently trying to develop the most efficient data model for our needs, this is the relationship between data elements.
We must adhere to a three-way relationship between users, items, and lists. A user can have many items and many lists. The list will have one user and many items. An item can belong to many users and many lists. The latter is especially important - an element can belong to a potentially huge number of lists: thousands, of course, and potentially tens or hundreds of thousands. Perhaps even millions in the future. We should be able to navigate these relationships in both directions: for example, get all the items in a list or all the lists to which the item belongs. We also need a common solution so that we can add a lot more types of documents and relationships to them if we need to.
So it seems that there are two possible solutions. Firstly, for each document in the database there is a collection of "relationships" consisting of an array of identifiers. Thus, in the list document, a collection of relations for elements with identifiers of all elements and a collection of relations with one identifier for the user will be created. In this model, these arrays will become massive when an item belongs to many, many users, or many, many lists.
The second model requires a new type of document, a “relationship” document, which stores the identifiers of each partner and the name of the relationship. This allows you to store more data in general and, thus, will affect disk space. It also looks like an “unnatural” way to approach this problem in NoSQL.
Efficiency, reasonable in area, architecture-wise, which is better and why?
Cheers, Matt
source share