Relationship 1: N and N: M MongoDB parse-server

0

I have two questions on how to model a mongo database Home 1:
In 1: N, with mongodb, should I save in the child entity the ID of the parent entity object, or the parent entity save an Array with the child IDs?

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

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. Home That's right? Can it cause errors? Or performance issues?

    
asked by anonymous 07.05.2017 / 16:20

1 answer

1

First of all, there is no specific rule for modeling in non-SQL databases. What you find are recommendations in the bank's documentation.

Speaking about MongoDB, there is a big general recommendation to follow: Always think about how data will be accessed / inserted / updated .

  • In 1: N relationships, in addition to following the general rule, also consider what size this N will be. Is there a list of dozens / 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 it will grow, it is better to use a separate collection. Speaking of the general rule: will your access always need children? use a subdocument. Are you going to get the father, and need your children every once in a while? 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 easily. Notice how the way you structure the schema is directly related to how you are going to access it.
  • About the N: N relationship, it is possible to implement as you did. You can also have a list of identifiers inside each object, on both sides. Here's even more the rule of how your application will access the information.
  • 07.05.2017 / 23:49