title: Mongoose nested model
body: <p>Not sure if this would be considered a dup, but I've searched around and implemented similar queries to what I find online but can't seem to get my nested reference to work.  I am simply testing to understand the mongoose syntax for populating both nested references and nested docs as discussed here: <a href="https://stackoverflow.com/questions/42290217/mongoose-nested-schema-vs-nested-models">Mongoose nested schema vs nested models</a></p>
  
  <p>However, I must be missing something because it seems to work but returns an empty array of nested references.  I know that my query should return two results for the nested reference.  </p>
  
  <ul>
  <li>What am I overlooking or doing wrong? </li>
  <li>How would I run my query differently if I wanted to use nested documents?</li>
  </ul>
  
  <p>Data:</p>
  
  <p>Result Collection:</p>
  
  <pre><code>{
      "_id" : ObjectId("5a4dcbe4ab9a793d888c9396"),
      "event_id" : ObjectId("5a482302a469a068edc004e3"),
      "event_name" : "Sample Event",
      "score" : "3-2",
      "winner" : "player1"
  },
  
  {
      "_id" : ObjectId("5a59791379cc1c321c1918f0"),
      "event_id" : ObjectId("5a482302a469a068edc004e3"),
      "event_name" : "Sample Event",
      "score" : "2-1",
      "winner" : "player2"
  }
  </code></pre>
  
  <p>Event Collection:</p>
  
  <pre><code>{
      "_id" : ObjectId("5a482302a469a068edc004e3"),
      "type" : "Tournament",
      "name" : "Sample Event"
  }
  </code></pre>
  
  <p>My code is as follows:</p>
  
  <pre><code>var mongoose = require("mongoose");
  mongoose.connect("MongoDB://localhost/devDB");
  
  var ResultSchema = mongoose.Schema({
      _id: mongoose.Schema.Types.ObjectId,
      event_id: {type: mongoose.Schema.Types.ObjectId, ref: "EventModel"},
      event_name: String,
      score: String,
      winner: String
  });
  
  var ResultModel = mongoose.model("results", ResultSchema);
  
  var EventSchema = mongoose.Schema({
      _id: mongoose.Schema.Types.ObjectId,
      name: String,
      type: String,
      results: [{type: mongoose.Schema.Types.ObjectId, ref: "ResultModel"}] 
  });
  
  var EventModel = mongoose.model("events", EventSchema);
  
  
  function GetEvent(eventid){
      // EventModel.findById(eventid)
      EventModel.findOne({_id: eventid})
          .populate("results","score winner", ResultModel)
          //.select("results") to extract only the nested references
          .exec(function(err, event){
              if (err){
                  console.log("ERROR fetching doc: ", err.name + ":  " + err.message)
              } else{
                  console.log(event);
              }
      });
  }
  
  GetEvent("5a482302a469a068edc004e3");
  </code></pre>
  
  <p>My output when I run it:</p>
  
  <pre><code>{ 
    results: [],
    _id: 5a482302a469a068edc004e3,
    type: 'Tournament',
    name: 'Test Tournament'
  }
  </code></pre>