@sealsystems/counter-storage
v0.0.8
Published
@sealsystems/counter-storage manages handling of counters persisted in a MongoDB
Downloads
3
Readme
@sealsystems/counter-storage
@sealsystems/counter-storage manages handling of counters persisted in a MongoDB.
Installation
$ npm install @sealsystems/counter-storage
Quick start
First you need to add a reference to @sealsystems/counter-storage within your application:
const counterStorage = require('@sealsystems/counter-storage');
Then you can connect to a MongoDB. For that call the connect
function and provide the database's connection string using the url
property:
const storage = await counterStorage.connect({
url: 'mongodb://localhost:27017'
});
Optionally, you may also specify the number of connection retries:
const storage = await counterStorage.connect({
url: 'mongodb://localhost:27017',
connectionRetries: 10
});
Get next counter value
To get the next counter value call the getCounter
function and provide its name. Optionally you can provide the increment as second argument, default increment is 1
:
const newCounterValue = await storage.getCounter('hugo');
With increment:
const newCounterValue = await storage.getCounter('hugo', 100);
Running the build
To build this module use roboter.
$ bot