0.0.2 • Published 1 year ago
mongoose-sequencer-tbs v0.0.2
Mongoose Sequencer TBS
Package for handling sequence number on mongodb with creating new collection that held all sequence key and counter.
Installation
Yarn
yarn add mongoose-sequencer-tbs
NPM
npm install mongoose-sequencer-tbs
Getting Started
Initialize package
import { MongooseSequencerInit } from 'mongoose-sequencer-tbs';
const init = await MongooseSequencerInit(
'mongodb://user:password@host:port?authMechanism=SCRAM-SHA-256&authSource=admin',
'db_name',
['user', 'order']
);
if (typeof init === 'string') {
throw new Error(init);
}
Get the next counter
import { MongooseSequencerNext } from 'mongoose-sequencer-tbs';
const seq = await MongooseSequencerNext('user');
const errorEx = await MongooseSequencerNext('not-registered-on-init');
console.log(seq) // 1 or 2 or 3 etc
console.log(errorEx) // Error instance with message `Sequence with key not-registered-on-init not found. Make sure you have registered the init function`