A
A
AlexZeDim2018-10-03 21:36:31
PostgreSQL
AlexZeDim, 2018-10-03 21:36:31

Design: How to make a one-to-one relationship within the same entity?

Hello! There is such a "problem".
There is a ready-made MongoDB collection and it has one entity: “items”.
3 attributes/fields: id, title(string), content(array).
The bottom line is that some items are made up of other items (they themselves cannot be classified according to any particular attribute). And this data must be stored somewhere and somehow, for example:
There is an item with id:1 an item with id:2. In order to get an item id: 3, you need to take an item with id: 1 in the amount of 3, and an item with id: 2 in the amount of 4.

id_1-(3)->Id_4
Id_2-(4)->Id_4

The fact is that graph DBMS like neo4j are great for solving this problem, the only problem is that it can not do everything that Mongo / Postgres can. Actually a question in how to store this data? In what form and what solution should be used? Changing Mongo to Postgres is not a problem. At the moment, my solution is to store arrays in the third attribute <content> as an array, like:

But maybe someone has a better idea or already an experienced solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-10-03
@AlexZeDim

Changing Mongo to Postgres is not a problem.

Good idea.
By the way, if your graphs are trees, Postgres can do them .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question