# mongo-incremental-id-generator

> Mongodb auto increment generator.

Latest version **0.1.0** (published 2016-01-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongo-incremental-id-generator
pnpm add mongo-incremental-id-generator
yarn add mongo-incremental-id-generator
bun add mongo-incremental-id-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2016-01-18 |
| First published | 2015-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Volodymyr Synytskyi |
| Maintainers | lionvs |
| Keywords | mongodb, id |

## Links

- npm: https://www.npmjs.com/package/mongo-incremental-id-generator
- Repository: https://github.com/lionvs/mongo-incremental-id-generator
- Issues: https://github.com/lionvs/mongo-incremental-id-generator/issues
- npm.io page: https://npm.io/package/mongo-incremental-id-generator

## Dependencies (2)

- [util](https://npm.io/package/util.md) ^0.10.3
- [mongojs](https://npm.io/package/mongojs.md) ^2.2.2

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2016-01-18
- 0.0.1 — 2015-12-23

## README

# mongo-incremental-id-generator

A [node.js](http://nodejs.org) module for mongodb, that generates auto incremental ids for specified string keys. 

[![Build Status](https://travis-ci.org/lionvs/mongo-incremental-id-generator.svg?branch=master)](https://travis-ci.org/lionvs/mongo-incremental-id-generator)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

Don't use this generator unless you actually need auto incremental ids because it will limit scalability as you are essentially creating a single point of failure/bottleneck where you are maintaining the sequence values for each key.

Can you re-use generator values?

Well – yes, technically you can. But – NO, you shouldn't. Never. Never ever. Not only that this would destroy the nice chronological sequence, the more you think about it the more headaches it'll give you. Moreover it is an absolute contradiction to the entire concept of unique identifiers.

So unless you have good reasons to re-use generator values, JUST DON'T DO IT!


## Usage

mongo-incremental-id-generator is very small mudule and easy to use:

```js
var idGenerator = require('mongo-incremental-id-generator')(connectionString)
```

The connection string should follow the format described in [the mongo connection string docs](http://docs.mongodb.org/manual/reference/connection-string/).

After we connected we can generate incremental ids for specific keys. Key is always string and step is always number.
The format for callbacks is always `callback(error, value)` where error is null if no exception has occured.

```js
// generate new id for the string key with increment step. By default step is equal to 1
idGenerator.generateId(key, step, function (err, id) {
	// id - auto generated id
})

idGenerator.generateId(key, function (err, id) {
})

// pick last generated id for the key
idGenerator.pickLastId(key, function (err, id) {
	// id - last generated id
})

// reset last generated id for the key to the newId. By default it resets to 0.
idGenerator.resetId(key, newId, function (err, id) {
	// id - newId
})

idGenerator.resetId(key, function (err, id) {
	// id - 0
})

---
_Source: https://npm.io/package/mongo-incremental-id-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
