Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 13, 2011 15:54
Show Gist options
  • Save aheckmann/1214180 to your computer and use it in GitHub Desktop.
Save aheckmann/1214180 to your computer and use it in GitHub Desktop.
var mongoose = require('./mongoose');
console.error(mongoose.version);
mongoose.connect('localhost', 'datevalueof');
function dateValueOf (d) {
console.error('date valueOf ran');
return d.valueOf();
}
var S = new mongoose.Schema({
dt: { type: Date, get: dateValueOf, default: Date.now }
});
var M = mongoose.model('datevalueof', S);
var m = new M({});
m.save(function (err) {
if (err) return console.error(err.stack || err);
M.findById(m._id, function (err, doc) {
if (err) return console.error(err.stack || err);
console.error('found %s', doc.dt);
var d = new Date(doc.dt);
console.error('new date: %s', d);
mongoose.connection.db.dropDatabase(function (err) {
console.error('dropped db');
mongoose.disconnect();
})
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment