npm install mongoose-date-plugin --save
'use strict';
module.exports = app => {
const mongoose = app.mongoose;
const UserSchema = new mongoose.Schema({
username: { type: String, required: true },
birthdate: { type: Date, default: new Date() },
...
});
return mongoose.model('User', UserSchema);
};
'use strict';
const mongooseDatePlugin = require('mongoose-date-plugin');
module.exports = app => {
const mongoose = app.mongoose;
const UserSchema = new mongoose.Schema({
username: { type: String, required: true },
birthdate: { type: Date, format: "YYYY-MM-DD" },
...
});
UserSchema.plugin(mongooseDatePlugin); // format: YYYY-MM-DD
return mongoose.model('User', UserSchema);
};
{
username: 'test',
birthdate: '2018-02-12',
...
}
more format looking for at moment