uploaded files to manage MongoDB database
This commit is contained in:
parent
c0c0085294
commit
8809c06912
2 changed files with 112 additions and 0 deletions
33
scripts/database/management/management.JS
Normal file
33
scripts/database/management/management.JS
Normal file
|
@ -0,0 +1,33 @@
|
|||
const Mongoose = require(`mongoose`);
|
||||
const CustomErrors = require(`../utilities/errors.JS`);
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
/*
|
||||
Establish the schema and collection. The result is stored in `this.#status`.
|
||||
|
||||
@param {string} COLLECTION the name of the collection
|
||||
@param {object} SCHEMA the scehma
|
||||
*/
|
||||
configure (COLLECTION, SCHEMA) {
|
||||
this[`schema`] = new Mongoose.Schema(SCHEMA);
|
||||
this[`collection`] = COLLECTION;
|
||||
this.state.then(() => {this.model = this[`connection`].model(`URL`, this[`schema`]);})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DBManagement;
|
Loading…
Add table
Add a link
Reference in a new issue