https://github.com/chapin666/mongoose-date-format
date format plugin for mongoose
https://github.com/chapin666/mongoose-date-format
date-formate eggjs mongoose-plugin
Last synced: about 1 year ago
JSON representation
date format plugin for mongoose
- Host: GitHub
- URL: https://github.com/chapin666/mongoose-date-format
- Owner: chapin666
- License: mit
- Created: 2018-06-12T09:50:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-12T14:00:50.000Z (about 8 years ago)
- Last Synced: 2024-10-18T14:54:11.035Z (over 1 year ago)
- Topics: date-formate, eggjs, mongoose-plugin
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoose-date-format
### INSTALL
```
npm install mongoose-date-format --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');
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',
...
}
```