<commit_before>var mongodb = require('mongodb');
var joi = require('joi');
var async = require('async');

var MongoClient = mongodb.MongoClient;
var ObjectID = mongodb.ObjectID;

var singleOption = joi.object({
    url: joi.string().default('mongodb://localhost:27017'),
    settings: joi.object()
});
var optionsSchema = joi.array().items(singleOption).min(1).single();

exports.register = function (plugin, pluginOptions, next) {

    optionsSchema.validate(pluginOptions, function (err, options) {

        if (err) {
            return next(err);
        }

        plugin.expose('lib', mongodb);
        plugin.expose('ObjectID', ObjectID);

        var connect = function (connectionOptions, done) {

            MongoClient.connect(connectionOptions.url, connectionOptions.settings, function (err, db) {

                if (err) {
                    return done(err);
                }

                plugin.log(['hapi-mongodb', 'info'], 'MongoClient connection created for ' + JSON.stringify(connectionOptions));
                done(null, db);
            });
        };

        async.map(options, connect, function (err, dbs) {

            if (err) {
                plugin.log(['hapi-mongodb', 'error'], err);
                return next(err);
            }

            plugin.expose('db', options.length === 1 ? dbs[0] : dbs);
            next();
        });
    });
};

exports.register.attributes = {
    pkg: require('../package.json')
};
<commit_msg>require promise library before each connection<commit_after>var mongodb = require('mongodb');
var joi = require('joi');
var async = require('async');

var MongoClient = mongodb.MongoClient;
var ObjectID = mongodb.ObjectID;

var singleOption = joi.object({
    url: joi.string().default('mongodb://localhost:27017'),
    settings: joi.object()
});
var optionsSchema = joi.array().items(singleOption).min(1).single();

exports.register = function (plugin, pluginOptions, next) {

    optionsSchema.validate(pluginOptions, function (err, options) {

        if (err) {
            return next(err);
        }

        plugin.expose('lib', mongodb);
        plugin.expose('ObjectID', ObjectID);

        var connect = function (connectionOptions, done) {

            if (connectionOptions.settings && typeof connectionOptions.settings.promiseLibrary === 'string') {
                connectionOptions.settings.promiseLibrary = require(connectionOptions.settings.promiseLibrary);
            }

            MongoClient.connect(connectionOptions.url, connectionOptions.settings, function (err, db) {

                if (err) {
                    return done(err);
                }

                plugin.log(['hapi-mongodb', 'info'], 'MongoClient connection created for ' + JSON.stringify(connectionOptions));
                done(null, db);
            });
        };

        async.map(options, connect, function (err, dbs) {

            if (err) {
                plugin.log(['hapi-mongodb', 'error'], err);
                return next(err);
            }

            plugin.expose('db', options.length === 1 ? dbs[0] : dbs);
            next();
        });
    });
};

exports.register.attributes = {
    pkg: require('../package.json')
};

{'fraction_non_alphanumeric': 0.1436120609263289, 'fraction_numerical': 0.004973577867578489, 'mean_word_length': 2.324380165289256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1243985', 'n_tokens_mistral': 932, 'n_tokens_neox': 867, 'n_words': 184}