I noticed that if I have the schema defined as Mixed {}
, that virtuals won't work.
var ArtistSchema = mongoose.Schema({
componists: {}
});
{
_id:1928319237192387,
componists:
{
name: 'George Enescu'
}
}
var find = function(req, res, next) {
return IP.findById(req.params.id, function(err, artist) {
if(!artist) {
res.status(404).send({
status: 'Not Found'
});
} else if (!err) {
console.log(JSON.stringify(artist.componists.name));
}
}
undefined
George Enescu
However logging artist.componists
works, giving back {name:'George Enescu'}
ArtistSchema.virtual('componists.familyName').get(function() {
return this.componists.split(' ')[1];
}