src/back/MongoAdapter.js
function closeConnection() {
    expect(arguments).to.have.length(
      0,
      'Invalid arguments length when closing a connection in a MongoAdapter ' +
      '(it has to be passed no arguments)'
    );

    return new Promise(function (resolve, reject) {
      if (_databaseIsLocked) {
        _databaseRequestQueue.push(function () {
          closeConnection()
            .then(resolve)
            .catch(reject);
        });
      } else if (!_database) {
        resolve();
      } else {
        _databaseIsLocked = true;
        _database
          .close()
          .then(function () {
            _database = null;
            _databaseIsLocked = false;
            resolve();
            _processDatabaseRequestQueue();
          })
          .catch(function (error) {
            _databaseIsLocked = false;
            reject(error);
            _processDatabaseRequestQueue();
          });
      }
    });
  }
function closeConnection() {
    expect(arguments).to.have.length(
      0,
      'Invalid arguments length when closing a connection in a MongoAdapter ' +
      '(it has to be passed no arguments)'
    );

    return new Promise(function (resolve, reject) {
      if (_databaseIsLocked) {
        _databaseRequestQueue.push(function () {
          closeConnection()
            .then(resolve)
            .catch(reject);
        });
      } else if (!_database) {
        resolve();
      } else {
        _databaseIsLocked = true;
        _database
          .close()
          .then(function () {
            _database = null;
            _databaseIsLocked = false;
            resolve();
            _processDatabaseRequestQueue();
          })
          .catch(function (error) {
            _databaseIsLocked = false;
            reject(error);
            _processDatabaseRequestQueue();
          });
      }
    });
  }
function closeConnection ( ) { expect ( arguments ) . to . have . length ( 0 , 'Invalid arguments length when closing a connection in a MongoAdapter ' + '(it has to be passed no arguments)' ) ; return new Promise ( function ( resolve , reject ) { if ( _databaseIsLocked ) { _databaseRequestQueue . push ( function ( ) { closeConnection ( ) . then ( resolve ) . catch ( reject ) ; } ) ; } else if ( ! _database ) { resolve ( ) ; } else { _databaseIsLocked = true ; _database . close ( ) . then ( function ( ) { _database = null ; _databaseIsLocked = false ; resolve ( ) ; _processDatabaseRequestQueue ( ) ; } ) . catch ( function ( error ) { _databaseIsLocked = false ; reject ( error ) ; _processDatabaseRequestQueue ( ) ; } ) ; } } ) ; }
Closes the current adapter' connection with MongoDB.
@name module:back4app-entity-mongodb.MongoAdapter#closeConnection
@function
@returns {Promise.<undefined|Error>} Promise that returns nothing if
succeed and the Error if failed.
@example
mongoAdapter.closeConnection()
.then(function () {
console.log('connection closed');
})
.catch(function (error) {
console.log(error);
});
Closes the current adapter connection with MongoDB .