title: How to remove document and all embedded documents in MongoDB?
body: <p>I have the following schema defined in Mongoose:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>var postSchema = mongoose.Schema({
    title: String,
    body: String,
    created: Date,
    photos: Array
  });
  
  var Post = mongoose.model('Post', postSchema);
  
  var photoSchema = mongoose.Schema({
    filename: String,
    mimetype: String,
    data: Buffer,
    created: Date
  });
  
  var Photo = mongoose.model('Photo', photoSchema);
  </code></pre>
  
  <p>If I remove a <code>Post</code>, I'd like all the related <code>Photo</code>s to be removed as well (like cascading delete in SQL).</p>
  
  <p>If I do <code>Post.remove({ _id: MY_POST_ID })</code>, only the <code>Post</code> gets removed and I have orphan <code>Photo</code>s left in the database.</p>
  
  <p>Also, should I somehow define the post ID in the <code>Photo</code> schema?</p>