# mongoose-date-plugin

> a plugin to format date type in mongodb

Latest version **1.0.2** (published 2023-06-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install mongoose-date-plugin
pnpm add mongoose-date-plugin
yarn add mongoose-date-plugin
bun add mongoose-date-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-06-04 |
| First published | 2023-06-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | itsheart |
| Maintainers | dawnsin |
| Keywords | mongoose, date, format, mongodb, express |

## Links

- npm: https://www.npmjs.com/package/mongoose-date-plugin
- Repository: https://github.com/ItsHeart/mongoose-date-plugin
- Homepage: https://github.com/ItsHeart/mongoose-date-plugin#readme
- Issues: https://github.com/ItsHeart/mongoose-date-plugin/issues
- npm.io page: https://npm.io/package/mongoose-date-plugin

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.29.4

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-06-04
- 1.0.1 — 2023-06-04
- 1.0.0 — 2023-06-04

## README

# mongoose-date-plugin

### INSTALL
```
npm install mongoose-date-plugin --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 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);
};
```


#### 3. response format:
```
{
  username: 'test',
  birthdate: '2018-02-12',
  ...
}
```
more format looking for at [moment](https://github.com/moment/moment)

---
_Source: https://npm.io/package/mongoose-date-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
