Skip to content

Instantly share code, notes, and snippets.

@S0c5
Created April 29, 2016 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save S0c5/6a5955d5a4817e457a42328a6e90e804 to your computer and use it in GitHub Desktop.
Save S0c5/6a5955d5a4817e457a42328a6e90e804 to your computer and use it in GitHub Desktop.
example default date with custom value
// before install : npm install moment --save
var mongoose = require('mongoose'),
moment = require('moment')
postSchema = new mongoose.Schema({
createdAt: {
type: Date,
default: Date.now
},
expiresAt: {
type: Date,
default: function(){
return new Date(moment().add(1, 'month').format());
}
}
});
module.exports = mongoose.model('post', postSchema);
@S0c5
Copy link
Author

S0c5 commented Apr 29, 2016

please add ',' after moment XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment