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

    return new Promise(function (resolve, reject) {
      if (_databaseIsLocked) {
        _databaseRequestQueue.push(function () {
          openConnection().then(resolve).catch(reject);
        });
      } else if (_database) {
        resolve();
      } else {
        _databaseIsLocked = true;

        MongoClient
          .connect(connectionUrl, connectionOptions)
          .then(function (database) {
            _database = database;
            _databaseIsLocked = false;
            resolve();
            _processDatabaseRequestQueue();
          })
          .catch(function (error) {
            _databaseIsLocked = false;
            reject(error);
            _processDatabaseRequestQueue();
          });
      }
    });
  }
function openConnection() {
    expect(arguments).to.have.length(
      0,
      'Invalid arguments length when opening a connection in a MongoAdapter ' +
      '(it has to be passed no arguments)'
    );

    return new Promise(function (resolve, reject) {
      if (_databaseIsLocked) {
        _databaseRequestQueue.push(function () {
          openConnection().then(resolve).catch(reject);
        });
      } else if (_database) {
        resolve();
      } else {
        _databaseIsLocked = true;

        MongoClient
          .connect(connectionUrl, connectionOptions)
          .then(function (database) {
            _database = database;
            _databaseIsLocked = false;
            resolve();
            _processDatabaseRequestQueue();
          })
          .catch(function (error) {
            _databaseIsLocked = false;
            reject(error);
            _processDatabaseRequestQueue();
          });
      }
    });
  }
function openConnection ( ) { expect ( arguments ) . to . have . length ( 0 , 'Invalid arguments length when opening a connection in a MongoAdapter ' + '(it has to be passed no arguments)' ) ; return new Promise ( function ( resolve , reject ) { if ( _databaseIsLocked ) { _databaseRequestQueue . push ( function ( ) { openConnection ( ) . then ( resolve ) . catch ( reject ) ; } ) ; } else if ( _database ) { resolve ( ) ; } else { _databaseIsLocked = true ; MongoClient . connect ( connectionUrl , connectionOptions ) . then ( function ( database ) { _database = database ; _databaseIsLocked = false ; resolve ( ) ; _processDatabaseRequestQueue ( ) ; } ) . catch ( function ( error ) { _databaseIsLocked = false ; reject ( error ) ; _processDatabaseRequestQueue ( ) ; } ) ; } } ) ; }
Connects the adapter with the targeted Mongo database.
@name module:back4app-entity-mongodb.MongoAdapter#openConnection
@function
@returns {Promise.<undefined|Error>} Promise that returns nothing if
succeed and the Error if failed.
@example
mongoAdapter.openConnection()
.then(function () {
console.log('connection opened');
})
.catch(function (error) {
console.log(error);
});
Connects the adapter with the targeted Mongo database .