Skip to content

Instantly share code, notes, and snippets.

@thatmarvin
Created March 26, 2012 11:50
Show Gist options
  • Save thatmarvin/2204602 to your computer and use it in GitHub Desktop.
Save thatmarvin/2204602 to your computer and use it in GitHub Desktop.
Mongoose does not populate virtuals? :(
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var UserSchema = new Schema({
name: {
first: {
type: String
},
last: {
type: String
}
}
});
User
.virtual('name.full')
.get(function () {
return [this.name.first, this.name.last].join(' ');
});
var ItemSchema = new Schema({
owner: {
type: Schema.ObjectId,
ref: 'User'
}
});
var ItemModel = mongoose.model('User', UserSchema);
ItemModel
.findById(id)
.populate('owner')
.run(function (err, item) {
console.log(item.user.full); // == undefined
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment