<commit_before>"use strict";
var fs = require('fs');
var Grid = require('gridfs-stream');

var soajs = require('soajs');
var Mongo = require("soajs").mongo;

var envCode = process.env.SOAJS_ENV || "dev";
envCode = envCode.toUpperCase();
function checkForMongoCore(config, req, cb) {
	var connectionInfo;
	
	var envInfo = req.soajs.registry;
	var dbInfo = config.db.config[envCode];
	var dbToUse = Object.keys(dbInfo)[0];
	for (var dbName in envInfo.dbs.databases) {
		if (dbName === dbToUse) {
			connectionInfo = envInfo.dbs.clusters[dbInfo[dbToUse].cluster];
			connectionInfo.name = dbToUse;
			
			if (dbInfo[dbToUse].tenantSpecific && req.soajs.urac) {
				var tenantCode = req.soajs.urac.tenant.code;
				connectionInfo.name = tenantCode + '_' + config.serviceName;
			}
		}
	}
	if (!connectionInfo) {
		return cb(new Error('This Environment has no Database Connection'));
	}
	return cb(null, connectionInfo);
}

function checkForMongoAndGridFs(config, req, inst, cb) {
	if (inst.config.db.multitenant) {
		checkForMongoCore(config, req, function (error, connectionInfo) {
			if (error) {
				return cb(error);
			}
			inst.mongo = new Mongo(connectionInfo);
			proceed();
		});
	}
	else {
		proceed();
	}
	
	function proceed() {
		inst.mongo.getMongoDB(function (error, db) {
			if (error) {
				return cb(error);
			}
			<commit_msg>fixes<commit_after>"use strict";
var fs = require('fs');
var Grid = require('gridfs-stream');

var soajs = require('soajs');
var Mongo = require("soajs").mongo;

var envCode = process.env.SOAJS_ENV || "dev";
envCode = envCode.toUpperCase();
function checkForMongoCore(config, req, cb) {
	var connectionInfo;
	
	var envInfo = req.soajs.registry;
	var dbInfo = config.db.config[envCode];
	var dbToUse = Object.keys(dbInfo)[0];
	for (var dbName in envInfo.coreDB) {
		if (dbName === dbToUse) {
			connectionInfo = envInfo.dbs.clusters[dbInfo[dbToUse].cluster];
			connectionInfo.name = dbToUse;
		}
	}
	
	if(!connectionInfo){
		for(var dbName in envInfo.tenantMetaDB){
			if (dbName === dbToUse) {
				connectionInfo = envInfo.dbs.clusters[dbInfo[dbToUse].cluster];
				var tenantCode = req.soajs.urac.tenant.code;
				connectionInfo.name = tenantCode + '_' + config.serviceName;
			}
		}
	}
	
	if (!connectionInfo) {
		return cb(new Error('This Environment has no Database Connection'));
	}
	return cb(null, connectionInfo);
}

function checkForMongoAndGridFs(config, req, inst, cb) {
	if (inst.config.db.multitenant) {
		checkForMongoCore(config, req, function (error, connectionInfo) {
			if (error) {
				return cb(error);
			}
			inst.mongo = new Mongo(connectionInfo);
			proceed();
		});
	}
	else {
		proceed();
	}
	
	function proceed() {
		inst.mongo.getMongoDB(function (error, db) {
			if (error) {
				return cb(error);
			}
			
{'fraction_non_alphanumeric': 0.14548073460568958, 'fraction_numerical': 0.0007202016564638099, 'mean_word_length': 4.097247706422018, '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': '184919', 'n_tokens_mistral': 1100, 'n_tokens_neox': 993, 'n_words': 207}