MongoDB - Model One-to-One, One-to-Many Relationships Embedded Documents | SpringBoot
With MongoDB, we can structure related data by embedded documents. In general, embedding gives a better performance for read operations. So in the tutorial, JavaSampleApproach will show you way to work with Embedded Documents using SpringBoot.
Related posts:
- Spring JPA One to Many Relationship
- SpringData MongoRepository
- SpringData MongoDB GridFsTemplate to save, retrieve, delete binary files (Image, Text files)
- Angular 4 + Spring Boot + MongoDB CRUD example
I. Technologies
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6RELEASE
– MongoDB: v3.4.1
II. MongoDB - Embedded Documents
Embedded Documents are generally known as denormalized models. It is a way to structure related data in a single document. See below diagram:
In general, we decide to design data as embedded models in case: data contains one-to-one or one-to-many relationships between entities.
With embedding data model, in general, it gives us a better performance for read operations. And we can use a single atomic read/write database operation to request and retrieve or update related data.
However, a weakness point is embedding related data in documents may lead to situations where documents grow after creation.
Top comments (0)