title: MongoDB relationships: embed or reference?
body: <p>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 comments: <code>embed</code> or <code>reference</code>?</p>
  
  <p>A question with some comments, like <a href="https://stackoverflow.com/">stackoverflow</a>, would have a structure like this:</p>
  
  <pre><code>Question
      title = 'aaa'
      content = bbb'
      comments = ???
  </code></pre>
  
  <p>At first, I want to use embeded comments (I think <code>embed</code> is recommended in MongoDB), like this:</p>
  
  <pre><code>Question
      title = 'aaa'
      content = 'bbb'
      comments = [ { content = 'xxx', createdAt = 'yyy'}, 
                   { content = 'xxx', createdAt = 'yyy'}, 
                   { content = 'xxx', createdAt = 'yyy'} ]
  </code></pre>
  
  <p>It clear, but I'm worried about this case: <strong>If I want to edit a specified comment, how do I get its content and its question?</strong> There is no <code>_id</code> to let me find one, nor <code>question_ref</code> to let me find its question. (I'm so newbie, that I don't know if there's any way to do this without <code>_id</code> and <code>question_ref</code>.)</p>
  
  <p>Do I have to use <code>ref</code> not <code>embed</code>? Then I have to create a new collection for comments?</p>