Created
September 2, 2011 14:16
-
-
Save aheckmann/1188699 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'); | |
mongoose.connect('localhost', 'testing_494'); | |
var Schema= mongoose.Schema; | |
function parseDate (v) { | |
return '2011-05-06'; | |
} | |
var ASchema = new Schema({ created: {type:Date, default: Date.now, get: parseDate} }) | |
var A = mongoose.model('A', ASchema); | |
mongoose.connection.on('open', function () { | |
var a = new A; | |
console.error('new', a); | |
a.save(function (err) { | |
if (err) return console.error(err.stack||err); | |
A.findById(a, function (err, a) { | |
if (err) return console.error(err.stack||err); | |
console.error('found', a); | |
console.error('get', a.created); | |
mongoose.connection.db.dropDatabase(function () { | |
mongoose.connection.close(); | |
}); | |
}); | |
}); | |
}); | |
/** | |
* prints | |
* | |
* new { _id: 4e60e5076c4c61ed3a000001, | |
* created: Fri, 02 Sep 2011 14:15:35 GMT } | |
* | |
* found { _id: 4e60e5076c4c61ed3a000001, | |
* created: Fri, 02 Sep 2011 14:15:35 GMT } | |
* | |
* get Fri, 06 May 2011 04:00:00 GMT | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment