@grammyjs/storage-mongodb
TypeScript icon, indicating that this package has built-in type declarations

2.4.2 • Public • Published

MongoDB storage adapter for grammY

Storage adapter that can be used to store your session data with MongoDB when using sessions.

Compatible with deno and node!

Installation

Node

npm install @grammyjs/storage-mongodb --save

Deno

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

Usage

You can see 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:

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 }),
}))

Readme

Keywords

none

Package Sidebar

Install

npm i @grammyjs/storage-mongodb

Weekly Downloads

421

Version

2.4.2

License

MIT

Unpacked Size

9.04 kB

Total Files

13

Last publish

Collaborators

  • knorpelsenf
  • satont