# mniam-store

> session store for connect middleware using mniam mongo access layer

Latest version **5.0.0** (published 2025-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install mniam-store
pnpm add mniam-store
yarn add mniam-store
bun add mniam-store
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities; has provenance.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2025-10-23 |
| First published | 2013-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Damian Krzeminski |
| Maintainers | pirxpilot |
| Keywords | mniam, connect, session, mongodb |

## Links

- npm: https://www.npmjs.com/package/mniam-store
- Repository: https://github.com/pirxpilot/mniam-store
- Homepage: https://github.com/pirxpilot/mniam-store#readme
- Issues: https://github.com/pirxpilot/mniam-store/issues
- npm.io page: https://npm.io/package/mniam-store

## Dependencies (1)

- [debug](https://npm.io/package/debug.md) ~4

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 5.0.0 (latest) — 2025-10-23
- 4.0.2 — 2025-06-02
- 4.0.1 — 2025-01-05
- 4.0.0 — 2023-12-25
- 3.0.1 — 2022-08-24
- 3.0.0 — 2022-06-03
- 2.0.0 — 2018-12-25
- 1.2.2 — 2017-02-23
- 1.2.1 — 2015-06-12
- 1.2.0 — 2015-06-11
- 1.1.0 — 2015-03-30
- 1.0.0 — 2015-03-28
- 0.1.0 — 2013-09-14

## README

[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]

# Mniam Store

mniam-store is a connect session store backed by [mongodb]

[mniam] is used to access as a access layer which means no async on init, simple configuration and
seamless connection sharing if your app is using DB

mniam-store is compatible with [express-session] middleware

## Installation

	  $ npm install mniam-store

## Options

- `db` existing database created with mniam (can be shared with other parst of the app)
- `collection` name of the mongo collection to keep sessions in (default: sessions)
- `maxAge` - (seconds) specifies how long sessions should stay in DB - should be set-up to a value slightly larger than `cookie.maxAge` - defaults to 1 day

## Usage

Similar to other connect [session][] stores.

```javascript
var connect = require('connect');
var mniam = require('mniam');
var MniamStore = require('mniam-store')(connect);

// use DB for mniam store only or share it with other parts of the app
var db = mniam.db('mongourl://localhost/database');

connect().use(connect.session({
  store: new MniamStore({
    db: db
  })
}));
```

## Upgrading from 0.x

Since `mniam-store` is using [mongo TTL index](http://docs.mongodb.org/manual/core/index-ttl/) sessions created with
previous versions will not expire automatically. We need to time stamp old sessions after the upgrade:

```javascript
db.sessions.update(
  {_mod: {$exists:0}},
  {$currentDate:{_mod:true}},
  {multi:true}
);
```

And drop old index in `expires`:

```javascript
db.sessions.dropIndex({expires:1});
```

# License

MIT

[express]: http://expressjs.com
[mongodb]: http://www.mongodb.org
[connect]: http://www.senchalabs.org/connect
[session]: http://www.senchalabs.org/connect/session
[mniam]: https://www.npmjs.com/package/mniam
[express-session]: https://www.npmjs.com/express-session

[npm-image]: https://img.shields.io/npm/v/mniam-store
[npm-url]: https://npmjs.org/package/mniam-store

[build-url]: https://github.com/pirxpilot/mniam-store/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/mniam-store/check.yaml?branch=main

[deps-image]: https://img.shields.io/librariesio/release/npm/mniam-store
[deps-url]: https://libraries.io/npm/mniam-store

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