issue.js
const mongoose;
const schema = new mongoose.Schema({
docs: {
type: [mongoose.Schema.Types.ObjectId],
refPath: 'coll',
required: true
},
coll: {
type: String,
required: true,
enum: ['Product', 'Service']
}
});
module.exports = mongoose.model('Issue', schema);
partial index.js
try{
let issues = await Issue.find().populate('docs');
console.log(issues);
//every issue in issues, has an empty 'docs' array, when it should consist of products/services that exist
}catch(e){}
Not sure why arrays is making it not work, I tried making the docs field as singular ObjectId, and it worked fine. Only thing I could think of is that because it's an array, the refPath has to be different, but I'm not sure what I could add, as I tried using 'this.coll'.