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

Latest commit

 

History

History
53 lines (44 loc) · 1.1 KB

README.md

File metadata and controls

53 lines (44 loc) · 1.1 KB

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