1 way
Comments are embedded in the Post document:
{
"_id": ObjectId(12345),
"title": "Cat ate elephant!",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean convallis pretium vulputate.",
"comments": [
{"name": "Cat", "body": "MEOW!"},
{"name": "Elephant", "body": "I was eaten by cat, lol!"},
{"name": "Human", "body": "I am hungry!"}
]
}
2 way
The relationship between mail and comments (in separate documents). The post has many comments:
{
"_id": ObjectId(12345),
"title": "Cat ate elephant!"
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean convallis pretium vulputate."
}
{
"_id": ObjectId(...),
"post_id": ObjectId(12345),
"name": "Cat",
"body": "MEOW!"
}
{
"_id": ObjectId(...),
"post_id": ObjectId(12345),
"name": "Elephant",
"body": "I was eaten by cat, lol!"
}
{
"_id": ObjectId(...),
"post_id": ObjectId(12345),
"name": "Human",
"body": "I am hungry!"
}
Which way is better?
source
share