- There are few ways to access virtual properties, try anything:
- Access manually
var docs = schema2model.find({}).populate('people');
console.log(docs[0].people.comment_count);
- Access using toObject method
var docs = schema2model.find({}).populate('people');
docs = docs.toObject({ virtuals: true });
console.log(docs);
- set
toObject: { virtuals: true }
property in your schema
let schema1 = new Schema({
comments: [{ type: Array }]
}, { toObject: { virtuals: true } });
- call your query after updating your schema
var docs = schema2model.find({}).populate('people');
console.log(docs);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…