Created
September 13, 2011 15:45
-
-
Save phillyqueso/1214162 to your computer and use it in GitHub Desktop.
mongoose getters, not working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I dont know if it is bug or a feature, but looks like getters work only when directly getting a property.