Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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插件。
- Host: GitHub
- URL: https://github.com/lqqyt2423/motime
- Owner: lqqyt2423
- Created: 2018-04-11T02:52:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-11T04:03:45.000Z (almost 7 years ago)
- Last Synced: 2024-04-26T11:21:10.872Z (9 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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