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:
Embedding: Through Embedding sub-documents, the One to Many relationship is achieved; this is the nested structure you are talking about;
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?
If the Sub Document that can be Embedding does not need to be queried separately, then Embedding directly;
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!
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:
Embedding: Through Embedding sub-documents, the One to Many relationship is achieved; this is the nested structure you are talking about;
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?
If the Sub Document that can be Embedding does not need to be queried separately, then Embedding directly;
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!