# @grammyjs/storage-mongodb

> MongoDB storage for grammy library.

Latest version **2.6.0** (published 2026-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @grammyjs/storage-mongodb
pnpm add @grammyjs/storage-mongodb
yarn add @grammyjs/storage-mongodb
bun add @grammyjs/storage-mongodb
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.6.0 |
| Published | 2026-07-15 |
| First published | 2022-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 627.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Satont <satontworldwide@gmail.com> |
| Maintainers | knorpelsenf, satont |

## Links

- npm: https://www.npmjs.com/package/@grammyjs/storage-mongodb
- Repository: https://github.com/grammyjs/storages
- Homepage: https://github.com/grammyjs/storages/tree/main/packages/mongodb#readme
- Issues: https://github.com/grammyjs/storages/issues
- npm.io page: https://npm.io/package/@grammyjs/storage-mongodb

## Recent versions

- 2.6.0 (latest) — 2026-07-15
- 2.5.1 — 2025-02-27
- 2.4.2 — 2024-02-29
- 2.4.1 — 2023-12-03
- 2.4.0 — 2023-10-09
- 2.3.2 — 2023-09-05
- 2.3.1 — 2023-08-29
- 2.3.0 — 2023-05-31
- 2.2.0 — 2023-04-15
- 2.1.4 — 2023-03-02
- 2.1.3 — 2023-03-02
- 2.1.1 — 2023-02-25
- 2.1.0 — 2023-01-16
- 2.0.2 — 2022-12-22
- 2.0.0 — 2022-05-06

## README

# MongoDB storage adapter for grammY

Storage adapter that can be used to
[store your session data](https://grammy.dev/plugins/session.html) with
[MongoDB](https://www.mongodb.com/) when using sessions.

Compatible with deno and node!

## Installation

Node

```bash
npm install @grammyjs/storage-mongodb --save
```

Deno

```ts
import { ISession, MongoDBAdapter } from 'https://deno.land/x/grammy_storages/mongodb/src/mod.ts'
```

## Usage

You can see [examples/](https://github.com/grammyjs/storages/tree/main/packages/mongodb/examples) which contains both Deno and Node examples.

### Mongoose

If you use Mongoose for operations with mongodb, you can still use this adapter.
You need to get a native connection and use it:

```ts
import mongoose from 'mongoose'
import { MongoDBAdapter, ISession } from '@grammyjs/storage-mongodb'

await mongoose.connect('mongodb://localhost:27017/test')

const collection = mongoose.connection.db.collection<ISession>('sessions')

bot.use(
	session({
		initial: (): SessionData => ({
			pizzaCount: 0,
		}),
		storage: new MongoDBAdapter({ collection }),
	})
)
```

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