<commit_before>'use strict'

import mongoose from 'mongoose'
import uriFormat from 'mongodb-uri'

import { config } from './'

config.mongo = config.get('mongo')

mongoose.set('useNewUrlParser', true)

export const connectionAgenda = mongoose.createConnection(encodeMongoURI(config.mongo.url))
export const connectionAPI = mongoose.createConnection(encodeMongoURI(config.mongo.url), getMongoOptions())
export const connectionATNA = mongoose.createConnection(encodeMongoURI(config.mongo.atnaUrl))
export const connectionDefault = mongoose.createConnection(encodeMongoURI(config.mongo.url))

function encodeMongoURI (urlString) {
  if (urlString) {
    let parsed = uriFormat.parse(urlString)
    urlString = uriFormat.format(parsed);
  }
  return urlString;
}

function getMongoOptions () {
  return {
    readPreference: config.mongo.openHIMApiReadPreference,
    readConcern: {level: config.mongo.openHIMApiReadConcern},
    w: config.mongo.openHIMApiWriteConcern
  }
}

if (process.env.NODE_ENV === 'test') {
  exports.encodeMongoURI = encodeMongoURI
}
<commit_msg>Add mongoose settings for mongodb<commit_after>'use strict'

import mongoose from 'mongoose'
import uriFormat from 'mongodb-uri'

import { config } from './'

config.mongo = config.get('mongo')

mongoose.set('useNewUrlParser', true)
mongoose.set('useUnifiedTopology', true)
mongoose.set('useFindAndModify', false)

export const connectionAgenda = mongoose.createConnection(encodeMongoURI(config.mongo.url))
export const connectionAPI = mongoose.createConnection(encodeMongoURI(config.mongo.url), getMongoOptions())
export const connectionATNA = mongoose.createConnection(encodeMongoURI(config.mongo.atnaUrl))
export const connectionDefault = mongoose.createConnection(encodeMongoURI(config.mongo.url))

function encodeMongoURI (urlString) {
  if (urlString) {
    let parsed = uriFormat.parse(urlString)
    urlString = uriFormat.format(parsed);
  }
  return urlString;
}

function getMongoOptions () {
  return {
    readPreference: config.mongo.openHIMApiReadPreference,
    readConcern: {level: config.mongo.openHIMApiReadConcern},
    w: config.mongo.openHIMApiWriteConcern
  }
}

if (process.env.NODE_ENV === 'test') {
  exports.encodeMongoURI = encodeMongoURI
}

{'fraction_non_alphanumeric': 0.10827740492170022, 'fraction_numerical': 0.0, 'mean_word_length': 6.053627760252366, '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': '3067476', 'n_tokens_mistral': 720, 'n_tokens_neox': 729, 'n_words': 130}