I started my studies in MongoDB recently and I didn't understand much better how we make the relationship between the entities that we have in the system.
So, as I am used to make this relationships in the SQL way, I get kind of confused when I change the logic to think in NoSQL way.
I saw that MongoDB has to types of modeling: Embedded and Referenced.
If I understand correct, Referenced is like we do in SQL:
Example: 1-to-N
Create two tables to represent the entities, like User and Address.
Create an user object and an address object
Put the Address ID into an user object
{
"_id":ObjectId("52ffc33cd85242f436000001"),
"contact": "987654321",
"dob": "01-01-1991",
"name": "Tom Benzamin",
"address_ids": [
ObjectId("52ffc4a5d85242602e000000"),
ObjectId("52ffc4a5d85242602e000001")
]
}
And the Embedded:
Create just one table, in this case User.
Create an user object and inside of it put the address object:
{
"_id":ObjectId("52ffc33cd85242f436000001"),
"contact": "987654321",
"dob": "01-01-1991",
"name": "Tom Benzamin",
"address": [
{
"building": "22 A, Indiana Apt",
"pincode": 123456,
"city": "Los Angeles",
"state": "California"
},
{
"building": "170 A, Acropolis Apt",
"pincode": 456789,
"city": "Chicago",
"state": "Illinois"
}]
}
So, my questions are:
To use the best features of a NoSQL Database like MongoDB, I have to use Embedded Modeling ?
In Embedded Modeling I just create only one Entity and the entity that is inside, the address object in this case, will not have an ID, since I didn't create a table ?