I want to design a question structure with some comments. Which relationship should I use for comments: embed
or reference
?
A question with some comments, like stackoverflow, would have a structure like this:
Question
title = 'aaa'
content = 'bbb'
comments = ???
At first, I thought of using embedded comments (I think embed
is recommended in MongoDB), like this:
Question
title = 'aaa'
content = 'bbb'
comments = [ { content = 'xxx', createdAt = 'yyy'},
{ content = 'xxx', createdAt = 'yyy'},
{ content = 'xxx', createdAt = 'yyy'} ]
It is clear, but I'm worried about this case: If I want to edit a specified comment, how do I get its content and its question? There is no _id
to let me find one, nor question_ref
to let me find its question. (Is there perhaps a way to do this without _id
and question_ref
?)
Do I have to use ref
rather than embed
? Do I then have to create a new collection for comments?