1:N and N:M Mongodb parse-server relationship

Asked

Viewed 634 times

0

I have two questions about modeling a database
1:
In 1: N, with mongodb, I must save in the child entity the ID of the parent entity object, or the parent entity save an Array with the child Ids?

In Parse-Server I could not make the result back a list with the Ids in the parent table, I found easier the daughter ID and search in the table all the results that have the parent table ID

2:
I read about Many-to-Many in Mongo, but in my db I did as SQL, I have a third table that stores the ID from the two tables.
Right? Can cause errors ? Or performance problems?

1 answer

1


First of all there is no specific rule for modeling on noSQL banks. What you find are recommendations in the database documentation.

Talking about Mongodb, there is a great general recommendation to follow: always think about how data will be accessed/entered/updated.

  1. In 1:N relationships, in addition to following the general rule, also consider how big that N will be. Will there be a list of tens/hundreds of children? consider using a subdocument (always remembering the maximum document size of 16MB). If the number of children is large (thousands, millions...), or you know you are going to grow, it is better to use a separate Collection. Speaking of the general rule: will your access ever need children? use an subdocument. Will you fetch the father, and need the children from time to time? use a separate Collection. Your proposals are also valid, saving the identifiers of the children in the father you can easily find the children of the objects, saving the father in the children you can "climb" in the relationship in an easy way. Notice how the way you structure the scheme is directly related to how you will access it.
  2. About the relationship N:N, it is possible to implement as you did yes. It is also possible to have a list of identifiers within each object, on both sides. Here is even more valid the rule of how your application will access the information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.