<commit_before>var Proto = require('uberproto');
var error = require('../errors');
var mongo = require('mongoskin');
var _ = require('underscore');

// TODO (EK): Does order matter for how these filters
// are applied? I think it does or at least it should.

var filters = {
  sort: function (values, param) {
    return _.sortBy(values, function (item) {
      return item[param];
    });
  },
  order: function (values) {
    return values.reverse();
  },
  skip: function (values, param) {
    return values.slice(param);
  },
  limit: function (values, param) {
    return values.slice(0, param);
  }
};

var MongoService = Proto.extend({

  // TODO (EK): How do we handle indexes?
  init: function (options) {
    options = options || {};

    this.type = 'mongo';
    this._id = options.idField || '_id';
    this.store = options.store || null;
    this.collection = options.collection || null;

    // TODO (EK): We need to get the collection somehow.
    // We have 3 options:
    //   1. Pass in the path on each request
    //   2. Initialize separate instances and pass it in there
    //   3. Set the collection when we register each service
    //
    // We are currently using option number 3. This could be bad.

    if (!this.store){
      this._connect(options);
    }
  },

  // NOTE (ek): We create a new database connection for every MongoService.
  // This may not be good but I think you could share connections by
  // passing the store as an option to the MongoService. The rational for this
  // design is because each user of a MongoService instance could be a separate
  // app residing on a totally different server.

  // TODO (EK): We need to handle replica sets.
  _connect: function(options){
    this.host = process.env.MONGO_HOST || options.host || 'localhost';
    this.port = process.env.MONGO_PORT || options.port || 27017;
    this.database = process.env.MONGO_DB || options.database || 'test';

    ackOptions = {
      w: options.w || 1,                  // write acknowledgment
      journal: options.journal || false,  // doesn't wait for journal before acknowledgment<commit_msg>changing the default database<commit_after>var Proto = require('uberproto');
var error = require('../errors');
var mongo = require('mongoskin');
var _ = require('underscore');

// TODO (EK): Does order matter for how these filters
// are applied? I think it does or at least it should.

var filters = {
  sort: function (values, param) {
    return _.sortBy(values, function (item) {
      return item[param];
    });
  },
  order: function (values) {
    return values.reverse();
  },
  skip: function (values, param) {
    return values.slice(param);
  },
  limit: function (values, param) {
    return values.slice(0, param);
  }
};

var MongoService = Proto.extend({

  // TODO (EK): How do we handle indexes?
  init: function (options) {
    options = options || {};

    this.type = 'mongo';
    this._id = options.idField || '_id';
    this.store = options.store || null;
    this.collection = options.collection || null;

    // TODO (EK): We need to get the collection somehow.
    // We have 3 options:
    //   1. Pass in the path on each request
    //   2. Initialize separate instances and pass it in there
    //   3. Set the collection when we register each service
    //
    // We are currently using option number 3. This could be bad.

    if (!this.store){
      this._connect(options);
    }
  },

  // NOTE (EK): We create a new database connection for every MongoService.
  // This may not be good but I think you could share connections by
  // passing the store as an option to the MongoService. The rational for this
  // design is because each user of a MongoService instance could be a separate
  // app residing on a totally different server.

  // TODO (EK): We need to handle replica sets.
  _connect: function(options){
    this.host = process.env.MONGO_HOST || options.host || 'localhost';
    this.port = process.env.MONGO_PORT || options.port || 27017;
    this.database = process.env.MONGO_DB || options.database || 'feathers';

    ackOptions = {
      w: options.w || 1,                  // write acknowledgment
      journal: options.journal || false,  // doesn't wait for journal before acknowledgment
{'fraction_non_alphanumeric': 0.11819887429643527, 'fraction_numerical': 0.005628517823639775, 'mean_word_length': 2.7944839857651247, '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': '6161818', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1192, 'n_words': 470}