lib/models/service.js
function initServiceModel(connectionUrl) {
  log.logger.debug("initServiceModel ", {connectionUrl: connectionUrl});
  if (!connectionUrl) {
    log.logger.error("No Connection Url Specified");
    return null;
  }

  //If the connection has not already been created, create it and initialise the Service Schema For That Domain
  if (!domainMongooseConnections[connectionUrl]) {
    log.logger.debug("No Connection Exists for " + connectionUrl + ", creating a new one");
    domainMongooseConnections[connectionUrl] = mongoose.createConnection(connectionUrl);
    domainMongooseConnections[connectionUrl].model(SERVICE_MODEL, ServiceSchema);

    //Setting Up Event Listeners
    domainMongooseConnections[connectionUrl].on('connecting', function(msg){
      log.logger.debug("Mongoose Connecting", {msg: msg, connectionUrl: connectionUrl});
    });

    domainMongooseConnections[connectionUrl].on('error', function(msg){
      log.logger.error("Mongoose Connection Error", {msg: msg, connectionUrl: connectionUrl});
    });

    domainMongooseConnections[connectionUrl].on('connected', function(msg){
      log.logger.debug("Mongoose Connected", {msg: msg, connectionUrl: connectionUrl});
    });
  } else {
    log.logger.debug("Connection Already Exists.");
  }

  return domainMongooseConnections[connectionUrl];
}
function initServiceModel(connectionUrl) {
  log.logger.debug("initServiceModel ", {connectionUrl: connectionUrl});
  if (!connectionUrl) {
    log.logger.error("No Connection Url Specified");
    return null;
  }

  //If the connection has not already been created, create it and initialise the Service Schema For That Domain
  if (!domainMongooseConnections[connectionUrl]) {
    log.logger.debug("No Connection Exists for " + connectionUrl + ", creating a new one");
    domainMongooseConnections[connectionUrl] = mongoose.createConnection(connectionUrl);
    domainMongooseConnections[connectionUrl].model(SERVICE_MODEL, ServiceSchema);

    //Setting Up Event Listeners
    domainMongooseConnections[connectionUrl].on('connecting', function(msg){
      log.logger.debug("Mongoose Connecting", {msg: msg, connectionUrl: connectionUrl});
    });

    domainMongooseConnections[connectionUrl].on('error', function(msg){
      log.logger.error("Mongoose Connection Error", {msg: msg, connectionUrl: connectionUrl});
    });

    domainMongooseConnections[connectionUrl].on('connected', function(msg){
      log.logger.debug("Mongoose Connected", {msg: msg, connectionUrl: connectionUrl});
    });
  } else {
    log.logger.debug("Connection Already Exists.");
  }

  return domainMongooseConnections[connectionUrl];
}
function initServiceModel ( connectionUrl ) { log . logger . debug ( "initServiceModel " , { connectionUrl : connectionUrl } ) ; if ( ! connectionUrl ) { log . logger . error ( "No Connection Url Specified" ) ; return null ; } //If the connection has not already been created, create it and initialise the Service Schema For That Domain if ( ! domainMongooseConnections [ connectionUrl ] ) { log . logger . debug ( "No Connection Exists for " + connectionUrl + ", creating a new one" ) ; domainMongooseConnections [ connectionUrl ] = mongoose . createConnection ( connectionUrl ) ; domainMongooseConnections [ connectionUrl ] . model ( SERVICE_MODEL , ServiceSchema ) ; //Setting Up Event Listeners domainMongooseConnections [ connectionUrl ] . on ( 'connecting' , function ( msg ) { log . logger . debug ( "Mongoose Connecting" , { msg : msg , connectionUrl : connectionUrl } ) ; } ) ; domainMongooseConnections [ connectionUrl ] . on ( 'error' , function ( msg ) { log . logger . error ( "Mongoose Connection Error" , { msg : msg , connectionUrl : connectionUrl } ) ; } ) ; domainMongooseConnections [ connectionUrl ] . on ( 'connected' , function ( msg ) { log . logger . debug ( "Mongoose Connected" , { msg : msg , connectionUrl : connectionUrl } ) ; } ) ; } else { log . logger . debug ( "Connection Already Exists." ) ; } return domainMongooseConnections [ connectionUrl ] ; }
Creating A connection To The Domain Database If It Does Not Already Exist
@param connectionUrl - Full Mongo Connection String For A Domain Database
@returns {null}
Creating A connection To The Domain Database If It Does Not Already Exist