MongoDB normalization, foreign key and joining

后端 未结 3 825
我寻月下人不归
我寻月下人不归 2020-12-02 09:33

Before I dive really deep into MongoDB for days, I thought I\'d ask a pretty basic question as to whether I should dive into it at all or not. I have basically no experience

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 10:31

    Above, @TomaaszStanczak states

    MongoDB doesn't support server side foreign key relationships, normalization is also discouraged. You should embed your child object within parent objects if possible, this will increase performance and make foreign keys totally unnecessary. That said it is not always possible ...

    Normalization is not discouraged by Mongo. To be clear, we are talking about two fundamentally different types of relationships two data entities can have. In one, one child entity is owned exclusively by a parent object. In this type of relationship the Mongo way is to embed.

    In the other class of relationship two entities exist independently - have independent lifetimes and relationships. Mongo wishes that this type of relationship did not exist, and is frustratingly silent on precisely how to deal with it. Embedding is just not a solution. Normalization is not discouraged, or encouraged. Mongo just gives you two mechanisms to deal with it; Manual refs (analoguous to a key with the foreign key constraint binding two tables), and DBRef (a different, slightly more structured way of doing the same). In this use case SQL databases win.

提交回复
热议问题