Skip to content

Instantly share code, notes, and snippets.

@bnoguchi
Created June 9, 2011 07:54
Show Gist options
  • Save bnoguchi/1016280 to your computer and use it in GitHub Desktop.
Save bnoguchi/1016280 to your computer and use it in GitHub Desktop.
Example demonstrating the request in mongoose GH-246 is now supported
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
var PageSchema = new Schema({
author: {
first_name: String
, last_name: String
}
});
PageSchema.virtual("author.full_name").get(function() {
return this.author.first_name + " " + this.author.last_name;
});
var Page = mongoose.model('Page', PageSchema);
// Later
myPage = new Page({author: {first_name: "John", last_name: "Doe"}});
console.log(myPage.author.full_name); // == "John Doe"
console.log(myPage.get("author.full_name")); // == "John Doe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment