This package brings auto increment functionality to MongoDb. It uses a collection (by default called counters
) to store the current the sequential number. Every collection, field or even custom filter can be managed separately.
Install
$ npm install mongo-autoincrement
Usage
The module exports just one function:
autoIncrementdb: Db, collection: string, field: string, options?)
You can call it like this:
;
Using more than one field for a counter
For example
await autoIncrementdb, 'test', 'id',
will add this counter:
Options
For more specific query and configuration you can pass custom options.
- filter: use this option if additional filters are needed.
- collectionName: sets autoIncrement collection name. Defaults to 'counters';
- step: lets you control the increse step. Defaults to 1;
License
MIT