Moving from version 1 to 2
Moving from the original version of abc.db to the new version
This guide assumes that you have imported abc.db like this:
//es6
import AbcDB from "abc.db";
//commonjs
const AbcDB = require("abc.db");
Step 1.1: Updating the constructor
The old abc.db constructor looks like this
const DB = new AbcDB("Mongo connection uri", "Mongoose options");
There is a simple change; now, you need to provide your preferred database name instead of mongoose options, as the package has changed which wrapper it uses
const DB = new AbcDB("Mongo connection uri", "your database name");
Step 1.2: Adding the connect method
In the new abc.db, you are required to connect to the database, and make sure that you await the method. Either use the await keyword or .then if it isn't in an asynchronous function:
await DB.connect();
//or
DB.connect().then(async() => {
//code here
})
Step 2: Updating Collections
In abc.db v1, a constructor was used for the collections, now it is a method inside the main class
const Collection = new DB.Collection("collection name"); //old
const Collection = DB.collection("collection name"); //new
It is quite simple to move over as the code above suggests
Step 3: Removing Events
In abc.db v1, you could use events which showed database related things, but so far I have found no way to use the same type of events on the mongodb wrapper, so they have been removed for now, so be sure to remove any code that says something along the lines of:
DB.on("event name", () => /* some code here */)
Last updated
Was this helpful?