Created
September 30, 2012 14:47
-
-
Save behrendtio/3806978 to your computer and use it in GitHub Desktop.
Mongoose date thing
This file contains 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'); | |
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); | |
}) | |
} |
This file contains 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
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