<commit_before>/**
  * MongoDB storage implementation.
  */

'use strict';

var mongodb = require('mongodb');
var BSON = mongodb.BSONPure;
var link = null;
var collection = null;
var maxResultSize = 100;

/**
 * In one or more documents, convert BSON Timestamp objects to their UNIX
 * timestamp integer values.
 *
 * @param docs {Array|Object} Query result(s).
 * @return {Array}
 */
var unpackTime = function(docs) {
  docs = _.isArray(docs) ? docs : [docs];
  docs = _.map(docs, function(doc) {
    doc.time = doc.time.high_;
    return doc;
  });
  return docs;
};

/**
 * Connect to the DB based on config.js. Reuse a link if available.
 *
 * @param callback {Function} Fired after connection attempted.
 */
var dbConnectAndOpen = function(callback) {
  if (link) {
    callback(null, link);
  } else {
    var config = helpers.getConfig().storage;
    collection = config.collection;
    link = new mongodb.Db(
      config.db,
      new mongodb.Server(config.host, config.port, {})<commit_msg>Fix array wrapping of single-doc result sets.<commit_after>/**
  * MongoDB storage implementation.
  */

'use strict';

var mongodb = require('mongodb');
var BSON = mongodb.BSONPure;
var link = null;
var collection = null;
var maxResultSize = 100;

/**
 * In one or more documents, convert BSON Timestamp objects to their UNIX
 * timestamp integer values.
 *
 * @param docs {Array|Object} Query result(s).
 * @return {Array}
 */
var unpackTime = function(docs) {
  if (_.isArray(docs)) {
    return _.map(docs, function(doc) {
      doc.time = doc.time.high_;
      return doc;
    });
  } else {
    docs.time = docs.time.high_;
    return docs;
  }
};

/**
 * Connect to the DB based on config.js. Reuse a link if available.
 *
 * @param callback {Function} Fired after connection attempted.
 */
var dbConnectAndOpen = function(callback) {
  if (link) {
    callback(null, link);
  } else {
    var config = helpers.getConfig().storage;
    collection = config.collection;
    link = new mongodb.Db(
      config.db,
      new mongodb.Server(config.host, config.port, {})
{'fraction_non_alphanumeric': 0.13121080559575493, 'fraction_numerical': 0.002894356005788712, 'mean_word_length': 3.25, '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': '2950154', 'n_tokens_mistral': 683, 'n_tokens_neox': 656, 'n_words': 203}