Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

TrejGun/trejgun-mongo-bot-storage

Folders and files

NameName
Last commit message
Last commit date
Sep 28, 2019
Feb 4, 2023
Feb 4, 2023
Feb 17, 2020
Aug 27, 2019
May 27, 2022
Aug 5, 2017
Nov 13, 2019
Jan 20, 2020
Oct 25, 2021
Nov 13, 2019
Nov 13, 2019
Aug 5, 2017
Aug 27, 2019
May 6, 2023
Oct 16, 2022

Repository files navigation

USAGE

es5

var storage = require("@trejgun/mongo-bot-storage");
var MongoDbBotStorage = storage.MongoDbBotStorage;
var MongoDBStorageClient = storage.MongoDBStorageClient;

es6

import {MongoDbBotStorage, MongoDBStorageClient} from "@trejgun/mongo-bot-storage";

new native connection

bot.set("storage", new MongoDbBotStorage(new MongoDBStorageClient({
    url: "mongodb://localhost/mydb",
    mongoOptions: {}
})));

mongoose connection

const connection = mongoose.createConnection(/* ... */);
bot.set("storage", new MongoDbBotStorage(new MongoDBStorageClient({
    mongooseConnection: connection
})));

db connection

MongoClient.connect("mongodb://localhost/mydb", (error, db) => {
    bot.set("storage", new MongoDbBotStorage(new MongoDBStorageClient({db})));
});

promise connection

const dbPromise = new Promise((resolve, reject) => {
	MongoClient.connect("mongodb://localhost/mydb", (error, db) => {
		if (error) {
			reject(error);
		} else {
			resolve(db);
		}
	});
});

bot.set("storage", new MongoDbBotStorage(new MongoDBStorageClient({dbPromise})));