MongoDB relationships: embed or reference?

后端 未结 11 2386
夕颜
夕颜 2020-11-21 05:34

I\'m new to MongoDB--coming from a relational database background. I want to design a question structure with some comments, but I don\'t know which relationship to use for

11条回答
  •  渐次进展
    2020-11-21 05:43

    If I want to edit a specified comment, how to get its content and its question?

    You can query by sub-document: db.question.find({'comments.content' : 'xxx'}).

    This will return the whole Question document. To edit the specified comment, you then have to find the comment on the client, make the edit and save that back to the DB.

    In general, if your document contains an array of objects, you'll find that those sub-objects will need to be modified client side.

提交回复
热议问题