Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><s>Looks like a bug. With debugging active, this is what's being shown for the population query:</p> <pre><code>Mongoose: people.findOne({ name: 'Billy' }) { fields: undefined } Mongoose: people.find({ _id: { '$in': [ ObjectId("52a221ee639cc03d71000001") ] } }) { fields: undefined } </code></pre> <p>(the <code>ObjectId</code> shown is the one stored in <code>bossStatus</code>)</p> <p>So Mongoose is querying the wrong collection (<code>people</code> instead of <code>bossstatuses</code>).</s></p> <p>As @regretoverflow pointed out, if you're looking for a boss, use the <code>Boss</code> model and not the <code>Person</code> model.</p> <p>If you do want to populate <code>bossStatus</code> through the <code>Person</code> model, you can explicitly state a model that needs to be searched for population:</p> <pre><code>.populate({ path : 'bossStatus', model : 'BossStatus' }) // or shorter but less clear: // .populate('bossStatus', {}, 'BossStatus') </code></pre> <p><strong>EDIT:</strong> (with your <code>Device</code> examples)</p> <p><code>driver</code> is part of <code>LocalDeviceSchema</code>, but you're querying the <code>Device</code> model, which has no notion of what <code>driver</code> is and populating <code>driver</code> within the context of a <code>Device</code> instance doesn't make sense to Mongoose.</p> <p>Another possibility for populating each instance is to do it after you retrieved the document. You already have the <code>deviceCallback</code> function, and this will probably work:</p> <pre><code>var deviceCallback = function(err, device) { if(err) { console.log(err); } switch(device.__t) { // or `device.constructor.modelName` case 'LocalDevice': device.populate('driver', ...); break; case 'RemoteDevice': device.populate('networkAddress', ...); break; } }; </code></pre> <p>The reason is that the document is already cast into the correct model there, something that apparently doesn't happen when you chain <code>populate</code> with the <code>find</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload