LearnBoost/mongoose — Issue #757: getters doesn't work (version: "2.5.9")
Author: dimik
Created: 2012-03-01 18:14:13+00:00
State: open

i need to make some strange hook for get them working
var mongoose = require('mongoose'),
express = require('express'),
app = express.createServer();

var unicornsSchema = new mongoose.Schema({
name : { type : String, get : function(s) { return s.substring(0, 2); } },
dob : Date,
loves : [String],
weigh : Number,
gender : String,
vampires : { type : Number, get : function(n) { return n + 1 } }
});

app.get('/', function(req, res) {
var db = mongoose.connect('mongodb://localhost/test'),
cursor = db.model('unicorns', unicornsSchema);

cursor.findOne({}, function(err, doc) {
doc.name = doc.name; // doesn't work without this
doc.vampires = doc.vampires; // the same for Numbers
res.contentType('json');
res.json({
success : !err,
result : doc
});
});
});

app.listen(3003);