title: Mongoose Schema Ref & Populate
body: <p>I would like to populate my database query with a set of documents from the same collection. Having never referenced before I can't tell if the error is in my model or in my query.</p>
  
  <p>My current schema looks like this,</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var mongoose = require('mongoose'),
      Schema = mongoose.Schema,
      shortid = require('shortid')
  
  /* Calendar Schema */
  var CalendarSchema = mongoose.Schema({
    _id: {
      type: String,
      unique: true,
      'default': shortid.generate
    }, 
    title:String,
    mixin: [{_id: { type: String, ref: 'calendarlist' }}],
    notes: Array
  })
  
  module.exports = mongoose.model('calendarlist', CalendarSchema)</code></pre>
  </div>
  </div>
  </p>
  
  <p>My sample docs looks like this,</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
      "_id" : "mixtest",
      "mixin" : [ 
          {
              "$ref" : "calendarlist",
              "$id" : "cVkKRkNtB-"
          }
      ],
      "title" : "mix test",
      "__v" : 3,
      "notes" : []
  }
  
  and
  
  
  {
      "_id" : "cVkKRkNtB-",
      "title" : "found doc",
      "__v" : 3,
      "notes" : []
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>and my query looks like this,</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>calendarlist.find({}).populate('mixin').sort({
                title: 1
              }).exec(function(err, s) {
                if (err) {console.log(err) }
                console.log(s)})</code></pre>
  </div>
  </div>
  </p>
  
  <p>Suggestions, tips or general clarifications totally appreciated. Thanks.</p>