A simple example is a forum without a complex structure. There is a "Subject" and there are "Answers".

  • Should there be two collections, with a one-to-many connection where the “ Answers ” refer to the “ Question ”? (Relational approach)
  • Or add answers to the " Answers " array for each question (composition)
  • Or make one collection (because the ticket differs little from the answer , then consider them as one entity) with the difference that the answers will have a link to the question ? (A kind of relational approach with a link within your collection)

For example, the second method raises a question for me: will it be convenient when I want to find a question on id .

Thank!

    1 answer 1

    Based on the material studied and communication on this topic I will give an answer to your question.

    It depends on how the entities will be used. Those. if we do not need to search for answers by id or another attribute, then we need a separate scheme, since access in this case will be impossible.

    The reason for the misunderstanding was that I assumed that even if the array was added to the record, it would be indexed.

    • even if an array is added to a record, it will be indexed. - Djn this is not entirely clear. Doesn't mongo index fields - arrays? - nikita