Skip to content

Instantly share code, notes, and snippets.

@behrendtio
Created September 30, 2012 14:47
Show Gist options
  • Save behrendtio/3806978 to your computer and use it in GitHub Desktop.
Save behrendtio/3806978 to your computer and use it in GitHub Desktop.
Mongoose date thing
var mongoose = require('mongoose');
var db = mongoose.createConnection('localhost', 'test');
var TestSchema = mongoose.Schema({
createdAt: {
type: 'date',
default: new Date()
}
});
var Test = db.model('Test', TestSchema);
console.log('Start: %s', new Date());
setTimeout(insert, 1000)
setTimeout(insert, 2000)
setTimeout(function() { db.close() }, 3000)
function insert() {
var test = new Test({});
test.save(function(err, doc) {
if (err) throw err;
console.log('Created at: %s', doc.createdAt);
})
}
Start: Sun Sep 30 2012 16:47:24 GMT+0200 (CEST)
Created at: Sun Sep 30 2012 16:47:24 GMT+0200 (CEST)
Created at: Sun Sep 30 2012 16:47:24 GMT+0200 (CEST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment