# @keyv/mongo

> MongoDB storage adapter for Keyv

Latest version **3.1.0** (published 2025-12-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @keyv/mongo
pnpm add @keyv/mongo
yarn add @keyv/mongo
bun add @keyv/mongo
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2025-12-26 |
| First published | 2017-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3200 |
| Author | Jared Wray |
| Maintainers | jaredwray |
| Keywords | mongo, mongodb, keyv, storage, adapter, key, value, store, cache, ttl |

## Links

- npm: https://www.npmjs.com/package/@keyv/mongo
- Repository: https://github.com/jaredwray/keyv
- Issues: https://github.com/jaredwray/keyv/issues
- npm.io page: https://npm.io/package/@keyv/mongo

## Dependencies (1)

- [mongodb](https://npm.io/package/mongodb.md) ^7.0.0

## 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

- 3.1.0 (latest) — 2025-12-26
- 6.0.0-rc.1 (rc) — 2026-08-03
- 6.0.0-beta.4 (beta) — 2026-06-18
- 6.0.0-alpha.3 (alpha) — 2026-03-22
- 3.0.0-rc.1 (next) — 2024-05-20
- 6.0.0-beta.3 — 2026-06-11
- 6.0.0-alpha.2 — 2026-03-04
- 6.0.0-alpha.1 — 2026-02-26
- 3.0.5 — 2025-10-03
- 3.0.4 — 2025-09-27
- 3.0.3 — 2025-06-10
- 3.0.2 — 2025-05-29
- 3.0.1 — 2024-08-21
- 3.0.0 — 2024-08-20
- 2.2.8 — 2023-05-21
- … 12 more at https://npm.io/package/@keyv/mongo/versions

## README

# @keyv/mongo [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)

> MongoDB storage adapter for Keyv

[![build](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
[![codecov](https://codecov.io/gh/jaredwray/keyv/branch/main/graph/badge.svg?token=bRzR3RyOXZ)](https://codecov.io/gh/jaredwray/keyv)
[![npm](https://img.shields.io/npm/v/@keyv/mongo.svg)](https://www.npmjs.com/package/@keyv/mongo)
[![npm](https://img.shields.io/npm/dm/@keyv/mongo)](https://npmjs.com/package/@keyv/mongo)

MongoDB storage adapter for [Keyv](https://github.com/jaredwray/keyv).

Uses TTL indexes to automatically remove expired documents. However [MongoDB doesn't guarantee data will be deleted immediately upon expiration](https://docs.mongodb.com/manual/core/index-ttl/#timing-of-the-delete-operation), so expiry dates are revalidated in Keyv.

## Install

```shell
npm install --save keyv @keyv/mongo
```

## Usage

```js
import Keyv from 'keyv';
import KeyvMongo from '@keyv/mongo';

const keyv = new Keyv(new KeyvMongo('mongodb://user:pass@localhost:27017/dbname'));
keyv.on('error', handleConnectionError);
```

You can specify the collection name, by default `'keyv'` is used.

e.g:

```js
const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname', { collection: 'cache' });
```

## License

[MIT © Jared Wray](LISCENCE)

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