mongoose-date-format-v2
v1.2.2
Published
### WHAT'S THED DIFFERENT WITH mongoose-date-format ``` return `` when the date value provided is undefined ```
Downloads
4
Maintainers
Readme
mongoose-date-format-v2
WHAT'S THED DIFFERENT WITH mongoose-date-format
return `` when the date value provided is undefined
INSTALL
npm install mongoose-date-format-v2 --save
USE
1. define schema:
'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);
};
2. added plugin:
'use strict';
const mongooseDateFormat = require('mongoose-date-format-v2');
module.exports = app => {
const mongoose = app.mongoose;
const UserSchema = new mongoose.Schema({
username: { type: String, required: true },
...
});
UserSchema.plugin(mongooseDateFormat); // format: YYYY-MM-DD HH:mm:ss
return mongoose.model('User', UserSchema);
};
3. response format:
{
username: 'test',
birthdate: '2018-02-12 19:23:45',
...
}