Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lqqyt2423/motime

Plugin for mongoose used to add createdAt and updatedAt to documents automatically. 用来自动给文档添加创建时间和更新时间的mongoose插件。
https://github.com/lqqyt2423/motime

Last synced: 20 days ago
JSON representation

Plugin for mongoose used to add createdAt and updatedAt to documents automatically. 用来自动给文档添加创建时间和更新时间的mongoose插件。

Awesome Lists containing this project

README

        

# Motime --- mongoose timestamp plugin

Used to add createdAt and updatedAt for documents before save or update, support following mongoose operation:

- Document.save()
- Model.create()
- Model.insertMany()
- Model.findOneAndUpdate()
- Model.findByIdAndUpdate()
- Model.update()
- Model.updateMany()
- Model.updateOne()

## Install

```
npm install motime --save
```

## Usage

```javascript
const timePlugin = require('motime');
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
name: String,
email: String
});

UserSchema.plugin(timePlugin);
mongoose.model('User', UserSchema);
```

You can also change the field name easily:

```javascript
UserSchema.plugin(timePlugin, {
createdAt: 'create_at',
updatedAt: 'updated_at'
});
```

## License

MIT