title: Use virtual property to access nested document in Mongoose model
body: <p>Im trying to create a virtual item in one of my schemas, that will need access to data thats referenced by an item thats referenced in this schema (Yes, thats 2 references deep, connecting 3 schemas/models)</p>
  
  <p>I've tried to simulate the code as close as I can here, using Model/Schema A/B/C..</p>
  
  <p>This would be the schema for the <strong>ModelA</strong>, which contains the virtual item which depends on the references:</p>
  
  <pre class="lang-js prettyprint-override"><code>// models/modela.js
  
  // SchemaA for ModelA
  const SchemaA = new Schema({
      _foo: {
          // References ModelB
          type: Schema.Types.ObjectId,
          ref: 'ModelB'
      }
  })
  
  // Virtual `Modela.something`, which needs the data from ModelC.baz
  SchemaA.virtual('something').get(function () {
      // How can I access ModelC.baz
      return 'Value from ModelC'
  });
  </code></pre>
  
  <p>Then heres the schema for <strong>ModelB</strong>:</p>
  
  <pre class="lang-js prettyprint-override"><code>// models/modelb.js
  
  // SchemaB for ModelB
  const SchemaB = new Schema({
      _bar: [{
          // References ModelC.baz
          type: Schema.Types.ObjectId,
          ref: 'ModelC'
      }]
  })
  </code></pre>
  
  <p>And the schema for <strong>ModelC</strong>:</p>
  
  <pre class="lang-js prettyprint-override"><code>// models/modelc.js
  
  // SchemaC for ModelC
  const SchemaC = new Schema({
      baz: Schema.Types.String
  })
  </code></pre>
  
  <p>As you can see above, what I need to do, is access <strong>Modelc.haz</strong> from within the virtual <code>something</code> item in <strong>ModelA</strong></p>
  
  <p>I thought that if I did both of the populations via the query itself, then maybe this would work, So I tried something like:</p>
  
  <pre class="lang-js prettyprint-override"><code>this.find()
      .populate( '_foo' )
      .populate( '_foo._bar' )
  </code></pre>
  
  <p>Which didn't work (which I actually didn't really expect it to, but oh well)</p>