const res = require('express/lib/response');
const { MongoClient, ObjectId } = require('mongodb');
function UserDB() {
MongoClient.connect('mongodb://localhost:7017', function (err, conn) {
if (err) throw err;
db = conn.db("mydb");
});
}
UserDB.prototype = {
findById: (req, callback) => {
const collection = db.collection('mycollection');
let oid = new ObjectId(req.params.myid);
collection
.find({ _id: oid })
.toArray(function (err, response) {
if (err) throw err;
console.log(response);
callback(response);
});
};
}
module.exports = new UserDB();