我是MongoDB新手——来自关系数据库背景.我想设计一个带有一些注释的问题 struct ,但我不知道使用哪个关系来进行注释:embed
还是reference
?
一个带有一些注释的问题,比如stackoverflow,其 struct 如下:
Question
title = 'aaa'
content = bbb'
comments = ???
首先,我想使用嵌入式注释(我认为MongoDB中建议使用embed
条),如下所示:
Question
title = 'aaa'
content = 'bbb'
comments = [ { content = 'xxx', createdAt = 'yyy'},
{ content = 'xxx', createdAt = 'yyy'},
{ content = 'xxx', createdAt = 'yyy'} ]
这很清楚,但我担心这个 case :If I want to edit a specified comment, how do I get its content and its question?没有_id
个让我找到一个,也没有question_ref
个让我找到它的问题.(我是个新手,我不知道没有_id
和question_ref
有没有办法做到这一点.)
我必须用ref
而不是embed
吗?然后我必须创建一个新的 comments 集?