0.0.6 • Published 3 years ago

@trejgun/mongo-bot-storage v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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