25
rated 0 times
[
27]
[
2]
/ answers: 1 / hits: 52226
/ 9 Years ago, mon, april 27, 2015, 12:00:00
In a mongoose schema such as:
var EventSchema = new Schema({
title: {
type: String,
default: '',
trim: true,
required: 'Title cannot be blank'
},
description: {
type: String,
default: '',
trim: true
},
start: {
type: Date,
default: Date.now,
required: 'Must have start date - default value is the created date'
},
end: {
type: Date,
default: Date.now + 7 Days, // Date in one week from now
required: 'Must have end date - default value is the created date + 1 week'
},
tasks: [{
type: Schema.ObjectId,
ref: 'Task'
}]
});
On the line for the end field the default date should set to +7 days. I can add presave hook and set it there, but wondering if theres a way to do this inline in the default field.
More From » mongoose