mongodb - What are the advantages of using nested structures in mongo
世界只因有你
世界只因有你 2017-05-02 09:26:28
0
2
833
{
    author{
        id,
        name,
    }
}

{
    author_id,
    author_name,
}

What are the advantages

世界只因有你
世界只因有你

reply all(2)
淡淡烟草味

First of all, you need to know that MongoDB is a type of NoSQL and does not directly support Join. This is a feature of NoSQL. It does not need to directly support Join and can achieve better horizontal expansion and performance.

But this does not mean that MongoDB cannot do what Join does. In order to achieve the function of traditional database join, MongoDB has two ideas:

  1. Embedding: Through Embedding sub-documents, the One to Many relationship is achieved; this is the nested structure you are talking about;

  2. Referencing: Referencing is divided into manual Referencing and automatic Referencing; manual Referencing is usually recommended, usually saving the Object_id of the document that needs to be associated in the Collection that needs to be associated, that is to say, when the Object_id of the Document that needs to be associated is written, respectively Written in two Collections that need to be related.

The above two ideas are also the main ideas of MongoDB’s Data Model.

So how to distinguish the above two ideas when they are used in specific applications?

  1. If the Sub Document that can be Embedding does not need to be queried separately, then Embedding directly;

  2. If this Sub Document needs to provide external queries, save it as a Collection separately and use Referencing to associate it with other collections.

For reference.

Love MongoDB! Have Fun!


See you there on the 19th, please click: >---<

MongoDB Online Lecture Series 19- MongoDB 10 steps to build a single view

左手右手慢动作

The document structure is closer to our description of object attributes; all attributes of an object can be described through one record, which is an advantage!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template