<commit_before>'use strict';

const logger = require( 'brinkbit-logger' )({ __filename, transport: 'production' });

const port = process.env.PORT || 3000;
const mongodb = {
    ip: process.env.MONGO_IP || 'localhost',
    port: process.env.MONGO_PORT || '27017',
    user: process.env.MONGO_USER,
    pass: process.env.MONGO_PASS,
};
mongodb.uri = mongodb.user && mongodb.pass ?
    `mongodb://${mongodb.user}:${mongodb.pass}@${mongodb.ip}:${mongodb.port}/test` :
    `mongodb://${mongodb.ip}:${mongodb.port}/test`;

function connect( mongooseConnection ) {
    return new Promise(( resolve, reject ) => {
        if ( mongooseConnection.readyState === 1 ) {
            logger.warning( 'Already connected. Resolving.' );
            return resolve();
        }

        const mongodbURI = mongodb.uri;

        logger.info( `Attempting to connect to: ${mongodbURI}` );
        mongooseConnection
        .removeAllListeners( 'connected' ).on( 'connected', () => {
            logger.info( 'Connected!' );
            resolve();
        })
        .removeAllListeners( 'error' ).on( 'error', ( err ) => reject( err ))
        .open( mongodbURI );
    });
}

function disconnect( mongooseConnection ) {
    return new Promise(( resolve, reject ) => {
        if ( mongooseConnection.readyState === 0 ) {
            logger.warning( 'No connection to disconnect. Resolving.' );
            return resolve();
        }

        logger.info( 'Closing mongoose connection' );
        mongooseConnection<commit_msg>Add configuration for mongo db<commit_after>'use strict';

const logger = require( 'brinkbit-logger' )({ __filename, transport: 'production' });

const port = process.env.PORT || 3000;
const mongodb = {
    ip: process.env.MONGO_IP || 'localhost',
    port: process.env.MONGO_PORT || '27017',
    user: process.env.MONGO_USER,
    pass: process.env.MONGO_PASS,
    database: process.env.MONGO_DB || 'test', 
};
mongodb.uri = mongodb.user && mongodb.pass ?
    `mongodb://${mongodb.user}:${mongodb.pass}@${mongodb.ip}:${mongodb.port}/${mongodb.database}` :
    `mongodb://${mongodb.ip}:${mongodb.port}/${mongodb.database}`;

function connect( mongooseConnection ) {
    return new Promise(( resolve, reject ) => {
        if ( mongooseConnection.readyState === 1 ) {
            logger.warning( 'Already connected. Resolving.' );
            return resolve();
        }

        const mongodbURI = mongodb.uri;

        logger.info( `Attempting to connect to: ${mongodbURI}` );
        mongooseConnection
        .removeAllListeners( 'connected' ).on( 'connected', () => {
            logger.info( 'Connected!' );
            resolve();
        })
        .removeAllListeners( 'error' ).on( 'error', ( err ) => reject( err ))
        .open( mongodbURI );
    });
}

function disconnect( mongooseConnection ) {
    return new Promise(( resolve, reject ) => {
        if ( mongooseConnection.readyState === 0 ) {
            logger.warning( 'No connection to disconnect. Resolving.' );
            return resolve();
        }

        logger.info( 'Closing mongoose connection' );
        mongooseConnection
{'fraction_non_alphanumeric': 0.15478484264611433, 'fraction_numerical': 0.007064868336544637, 'mean_word_length': 2.7260765550239237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6280350', 'n_tokens_mistral': 976, 'n_tokens_neox': 922, 'n_words': 200}