FCC-Project-URLShortener/scripts/database/management.js
2025-03-23 07:48:47 +00:00

21 lines
No EOL
706 B
JavaScript

const Mongoose = require(`mongoose`);
const CustomErrors = require(`../utilities/errors`).CustomErrors;
class DBManagement {
/*
Begin the connection.
@param {string} DOMAIN the domain
@param {string} DBNAME the database name
*/
constructor (DOMAIN, DBNAME) {
const throwError = (ERROR) => {throw ERROR;};
this[`state`] = Mongoose.connect(`mongodb://${DOMAIN}/${(DBNAME) ? DBNAME : ""}`, { useNewUrlParser: true, useUnifiedTopology: true }).then((CONNECTION) => {
this[`connection`] = CONNECTION.connection;
console.log(`Connection successful.`);
}).catch(throwError);
};
}
module.exports = {DBManagement};