我将代码中的一个问题归结为基本要素:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var get_dob = function(date) {
return "" + (date.getMonth() + 1) + "/" + (date.getDate()) + "/" + (date.getFullYear());
};
FooSchema = new Schema({
dob: { type: Date, get: get_dob }
});
mongoose.connect("mongodb://127.0.0.1/test");
Foo = mongoose.model('Foo', FooSchema);
Foo.remove({}, function(err) {
var f;
f = new Foo({
dob: Date.now()
});
f.save(function(err) {
Foo.findOne({}, function(err, doc) {
console.log(doc.toObject({
getters: true
}));
});
});
});
日期的输出是:
Mon, 07 May 2012 07:00:00 GMT
为什么不应用吸气剂?