Now that you've proved you have a working MongoDB server, let's get to work.
Installing the Node.js driver is as simple as running the following command:
$ npm install mongodb@3.x --save
Now create a new file, models/notes-mongodb.mjs:
import util from 'util';import Note from './Note';import mongodb from 'mongodb'; const MongoClient = mongodb.MongoClient;import DBG from 'debug';const debug = DBG('notes:notes-mongodb'); const error = DBG('notes:error-mongodb'); var client;async function connectDB() { if (!client) client = await MongoClient.connect(process.env.MONGO_URL); return { db: client.db(process.env.MONGO_DBNAME), client: client };}
The MongoClient class is used to connect with a MongoDB instance. ...