text: /** Class containing database functions.
   */
  
  module.exports = class DataBase{
      /**
       * Create a DataBase class.
       * @param {string} client - The client.
       * @param {string} dbName - The name of the database.
       * @param {string} url - The url to connect to.
       */
      constructor(client, dbName, url){
          this.client = client;
          this.connection = null;
          this.url = url;
          this.dbName = dbName;
          this.connectedDB = null;
      }
      /**
       * inserts a document with _id as _id into the database
       * @param {string} _id
       * @return {void}
       */
      insertDocuments(_id) {
          const collection = this.connectedDB.collection('documents');
          collection.insertOne({_id:_id}).catch();
      }
      /**
       * updates a document with id and obj
       * @param {number} id
       * @param {string} obj
       * @return {void}
       */
      updateDocuments(id, obj) {
          const collection = this.connectedDB.collection('documents');
          collection.updateOne({_id:id},{$set:obj},{upsert:true}).catch()
      }
      /**
       * returns object of the document
       * @param {string} obj
       * @return {object}
       */
      async getOneDocument(obj){
          const collection = this.connectedDB.collection('documents');
          const doc = await collection.find(obj).limit(1).next();
          return doc;
      }
      /**
       * connects to the databse or local
       */
      async connect(){
          try{
              this.connection = await this.client.connect(this.url, {useNewUrlParser:true});
          }catch{
              console.log("error could not connect to db, switching to local db instead");
              this.connection = await this.client.connect("mongodb://localhost:27017/db", {useNewUrlParser:true});
          }
  
          if(this.connection){
              console.log("connected to db");
              this.connectedDB = this.connection.db(this.dbName);
          }
      }
      /**
       * returns number that is unused in the database
       * @param {number} id
       * @return {number}
       */
      async getUnusedID(id = 0){
          const doc = await this.getOneDocument({_id:id});
          if(doc){
              id = await this.getUnusedID(++id);
          }
          return id;
      }
      /**
       * closes connection to the database
       */
      close(){
          this.connection.close();
          console.log("closed db");
      }
  }