title: Mongoose - populate method
body: <p>I have a <code>comments</code> collection with custom values for <code>_id</code> instead of mongo objectIds:</p>
  
  <pre><code>var exports = module.exports = CommentsSchema = new mongoose.Schema({});
  CommentsSchema.add({
  _id : {type : Number, required : true, index: true, unique : true },
  label:      {type: String, index: true, unique : true }//Should be unique
  });
  </code></pre>
  
  <p>Records:</p>
  
  <pre><code>db.comments.insert{_id:1, label : 'some text'});
  db.comments.insert({_id:2, label : 'some text'});
  </code></pre>
  
  <p>Another schema <code>Posts</code> which refers <code>Comments</code> as below</p>
  
  <pre><code>PostsSchema.add({
      comments : [{type : Number, ref: 'Comments' }],
  });
  </code></pre>
  
  <p>I tried to use <code>mongoose.populate</code> method to get Comments data along with Posts data. But as I have custom ID for comments, I am not getting the comments data in posts.</p>
  
  <pre><code>Posts.find().populate('Comments').exec(function(err, posts){
  console.log(posts);
  });
  </code></pre>
  
  <p>I checked <a href="http://mongoosejs.com/docs/api.html#model_Model.populate" rel="nofollow">mongoose populate docs</a>, which defines multiple options that can be passed for populate, but could not get that working as well. Is it possible to use <code>populate</code> method for custom defined "_id" or custom fields? </p>
  
  <p><strong>Final Solution</strong>
  Using <code>CommentsSchema</code> and <code>PostsSchema</code> as as above, i got this working with below code.</p>
  
  <pre><code>Posts.find({}).populate('comments').exec(function(err, posts){
      console.log(posts);
      });
  </code></pre>