title: How to populate a sub-document in mongoose after creating it?
body: <p>I am adding a comment to an item.comments list. I need to get the comment.created_by user data before I output it in the response. How should I do this?</p>
  
  <pre><code>    Item.findById(req.param('itemid'), function(err, item){
          var comment = item.comments.create({
              body: req.body.body
              , created_by: logged_in_user
          });
  
          item.comments.push(comment);
  
          item.save(function(err, item){
              res.json({
                  status: 'success',
                  message: "You have commented on this item",
  
  //how do i populate comment.created_by here???
  
                  comment: item.comments.id(comment._id)
              });
          }); //end item.save
      }); //end item.find
  </code></pre>
  
  <p>I need to populate the comment.created_by field here in my res.json output:</p>
  
  <pre><code>                comment: item.comments.id(comment._id)
  </code></pre>
  
  <p>comment.created_by is a user reference in my mongoose CommentSchema. It currently is only giving me a user id, I need it populated with all the user data, except for password and salt fields.</p>
  
  <p>Here is the schema as people have asked:</p>
  
  <pre><code>var CommentSchema = new Schema({
      body          : { type: String, required: true }
    , created_by    : { type: Schema.ObjectId, ref: 'User', index: true }
    , created_at    : { type: Date }
    , updated_at    : { type: Date }
  });
  
  var ItemSchema = new Schema({
      name    : { type: String, required: true, trim: true }
    , created_by  : { type: Schema.ObjectId, ref: 'User', index: true }
    , comments  : [CommentSchema]
  });
  </code></pre>