<commit_before>var instances = [];
var orig = Mongo.Collection;

var spawner = function(name, options) {
  return spawn(name, options);
};

var spawn = function(name, options) {
  Mongo.Collection = orig;
  var instance = new Mongo.Collection(name, options);
  instances.push({
    name: name,
    instance: instance,
    options: options
  });
  Mongo.Collection = spawner;
  return instance;
};

Mongo.Collection = spawner;
for (var property in orig) {
  if (orig.hasOwnProperty(property))
    Mongo.Collection[property] = orig[property];
}

Mongo.Collection.get = function(name, options) {
  options = options || {};
  var collection = _.find(instances, function(instance) {
    if (options.connection)
      return instance.name === name &&
        instance.options && instance.options.connection._lastSessionId === options.connection._lastSessionId;
    return instance.name === name;
  });

  if (! collection)
    throw new Meteor.Error("Collection not found");

  return collection.instance;
};

Mongo.Collection.getAll = function() {
  return instances;
};

if (Meteor.users) {
  instances.push({
    name: 'users',
    instance: Meteor.users,
    options: undefined
  });
}
<commit_msg>Added support for Meteor.Collection<commit_after>var instances = [];
var orig = Mongo.Collection;

var spawner = function(name, options) {
  return spawn(name, options);
};

var spawn = function(name, options) {
  Mongo.Collection = orig;
  var instance = new Mongo.Collection(name, options);
  instances.push({
    name: name,
    instance: instance,
    options: options
  });
  Mongo.Collection = spawner;
  return instance;
};

Mongo.Collection = spawner;
Meteor.Collection = spawner;

for (var property in orig) {
  if (orig.hasOwnProperty(property))
    Mongo.Collection[property] = orig[property];
}

Mongo.Collection.get = function(name, options) {
  options = options || {};
  var collection = _.find(instances, function(instance) {
    if (options.connection)
      return instance.name === name &&
        instance.options && instance.options.connection._lastSessionId === options.connection._lastSessionId;
    return instance.name === name;
  });

  if (! collection)
    throw new Meteor.Error("Collection not found");

  return collection.instance;
};

Mongo.Collection.getAll = function() {
  return instances;
};

if (Meteor.users) {
  instances.push({
    name: 'users',
    instance: Meteor.users,
    options: undefined
  });
}

{'fraction_non_alphanumeric': 0.13338788870703763, 'fraction_numerical': 0.0, 'mean_word_length': 3.8705179282868527, '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': '7105629', 'n_tokens_mistral': 735, 'n_tokens_neox': 724, 'n_words': 179}