title: Insert and return ID of sub-document in MongoDB document sub-document array
body: <p>My node.js application will insert a sub-document into a nested sub-document array field of the following MongoDB document, and I need to determine the ID of the newly inserted sub-document:</p>
  
  <pre><code>{
    "_id" : ObjectId("578d5a52cc13117022e09def"),
    "name" : "Grade 5 - Section A",
    "scores" : [{
      "studentId" : ObjectId("5776bd36ffc8227405d364d2"),
      "performance" : [{
        "_id" : ObjectId("57969b8fc164a21c20698261"),
        "subjectId" : ObjectId("577694ecbf6f3a781759c54a"),
        "score" : 86,
        "maximum" : 100,
        "grade" : "B+"
      }]
    }]
  }
  </code></pre>
  
  <p>The sub-document looks like this:</p>
  
  <pre><code>{
    "subjectId" : ObjectId("5776ffe1804540e29c602a62"),
    "score" : 74,
    "maximum" : 100,
    "grade" : "A-"
  }
  </code></pre>
  
  <p>I am adding the sub-document using the following Mongoose code:</p>
  
  <pre><code>Class.update({
    _id: '578d5a52cc13117022e09def',
    'scores.studentId': '5776bd36ffc8227405d364d2'
  }, {
    $addToSet: {
      'scores.$.performance': {
        'subjectId' : '5776ffe1804540e29c602a62',
        'score' : 74,
        'maximum' : 100,
        'grade' : 'A-'
      }
    }
  }, function(err, result) {
    if (err) {
      throw err;
    }
    console.log(result);
  });
  </code></pre>
  
  <p>The <em>subject</em> sub-document gets added in the <code>performance</code> sub-document array which is itself nested in the <code>scores</code> sub-document array. Notice that the newly inserted sub-document is assigned with its own ID, as instituted by the defined schema. Even if I get back the entire document, that's not very helpful. I specifically need the ID of that newly inserted sub-document. What is the recommended approach to this problem?</p>