Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r3wt/mongoose-auto-increment-2
yet another mongoose-auto-increment plugin
https://github.com/r3wt/mongoose-auto-increment-2
Last synced: about 2 months ago
JSON representation
yet another mongoose-auto-increment plugin
- Host: GitHub
- URL: https://github.com/r3wt/mongoose-auto-increment-2
- Owner: r3wt
- Created: 2017-09-17T22:44:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-16T20:55:36.000Z (over 6 years ago)
- Last Synced: 2024-10-03T03:44:38.246Z (3 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
### download
-------
```js
npm i --save mongoose-auto-increment-2
```### why
-------
1. the available mongoose auto increment plugins seem to not be maintained.
2. none of them use a sparse index, which can lead to chaos in case of null fields.
3. none of the plugins self heal the index.
4. no ability to change name of counters collection, which could matter for some people.
5. none prevent modification of the index field### usage
-------**plugin usage**
```jsvar mongoose = require('mongoose');
var autoincrement = require('mongoose-auto-increment-2');
var PersonSchema = new mongoose.Schema({
name : { type: String }
});PersonSchema.plugin(autoincrement,{ field: 'id' });
var Person = mongoose.model('Person',PersonSchema);
```**healing collection**
```js
var Person = require('mongoose').model('Person');
//selfheal collection
Person.heal().then((numSaved)=>{
console.log('%d documents healed',numSaved);
});
```
**changing name of collection**
```js
var autoincrement = require('mongoose-auto-increment-2');
autoincrement.setCollection('custom-counters');
```