const MongoClient = require("mongodb").MongoClient; const ObjectID = require("mongodb").ObjectID; const mm = require('mm') module.exports = async (dbName, dsn="mongodb://localhost:27017/") => { if (!dbName) throw new ReferenceError(`db name does not provided`) const mongoClient = new MongoClient(dsn, { useNewUrlParser: true }); const client = await mongoClient.connect() const db = client.db(dbName) const Savable = mm(db).Savable const sliceSavable = mm(db).sliceSavable return { Savable, slice(...params){ return sliceSavable(...params) } } }