我已经使用 mongoDB 连接创建了一个数据库类,但我不知道如何在这种情况下打开一个数据库实例。
import mongo from 'mongodb'
import Grid from 'gridfs-stream'
export default class Db {
constructor () {
this.connection = new mongo.Db('db', new mongo.Server('127.0.0.1', 27017))
}
async dropDB () {
const Users = this.connection.collection('users')
await Users.remove({})
}
}
我如何在课堂上使用它?
db.open(function (err) {
if (err) return handleError(err);
var gfs = Grid(db, mongo);
})