Skip to content

Instantly share code, notes, and snippets.

@phillyqueso
Created September 13, 2011 15:45
Show Gist options
  • Save phillyqueso/1214162 to your computer and use it in GitHub Desktop.
Save phillyqueso/1214162 to your computer and use it in GitHub Desktop.
mongoose getters, not working.
var mongoose = require('mongoose'),
db = mongoose.connect('mongodb://localhost/blog'),
Schema = mongoose.Schema,
fields = ['createdDate', 'canComment', 'story', 'title', 'user'];
var commentsSchema = new Schema({
user : { type: String },
comment : { type: String },
createdDate : { type: Date, default: Date.now }
});
var postsSchema = new Schema({
user : { type: String },
title : { type: String },
story : { type: String },
canComment: { type: Boolean },
createdDate : { type: Date, get: function(dt) { return dt.valueOf(); }, default: Date.now },
comments: [commentsSchema]
});
var Posts = mongoose.model('posts', postsSchema);
Posts.find({}, fields).limit(10).execFind(function(err, res) {
if (res != null) {
console.log(res);
}
});
@jsmarkus
Copy link

jsmarkus commented Nov 3, 2011

I dont know if it is bug or a feature, but looks like getters work only when directly getting a property.

JSON.stringify(doc); //not working

doc.propertyWithGetter; //working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment