Mongo.Collection.prototype.helpers = function(helpers) {
  var self = this;

  if (self._transform && ! self._helpers)
    throw new Meteor.Error("Can't apply helpers to '" +
      self._name + "' a transform function already exists!");

  if (! self._helpers) {
    self._helpers = function Document(doc) { return _.extend(this, doc); };
    self._transform = function(doc) {
      return new self._helpers(doc);
    };
  }

  _.each(helpers, function(helper, key) {
    self._helpers.prototype[key] = helper;
  });
};

Mongo.Collection.prototype.helpers = function(helpers) {
  var self = this;

  if (self._transform && ! self._helpers)
    throw new Meteor.Error("Can't apply helpers to '" +
      self._name + "' a transform function already exists!");

  if (! self._helpers) {
      self._helpers = function Document(doc) {
          console.log(this);
      };
    self._transform = function(doc) {
      return new self._helpers(doc);
    };
  }

  _.each(helpers, function (helper, key) {
      var path = key.split(".");
      if (path.length === 1) {
          // key is root
          if (self._helpers.prototype[key]) {
              console.error("Cannot add helper at" + key + ". Helpers cannot override existing properties");
              return;
          }
          self._helpers.prototype[key] = helper;
          return;
      } else {
          // key is nested
          self._helpers._nestedHelperTree = self._helpers._nestedHelperTree || {};
          var tree = self._helpers._nestedHelperTree;
          for (var i = 0; i < path.length; i++) {
              if (i === path.length - 1) {
                  if (tree[path[i]]) {
                      console.error("Cannot add helper at" + key + ". Helper already defined");
                      return;
                  } else {
                      tree[path[i]] = helper;
                  }
              } else {
                  if (!tree[path[i]]) {
                      tree[path[i]] = {};
                  }
                  tree = tree[path[i]];
              }
          }
      }
  });
};

Build up nested helper tree.
Build up nested helper tree.

This step builds a object tree from the nested paths provided to helpers and attaches it to the _helpers object.

example:
// For the following call
collectionName.helpers({
   "rootHelper": function A(){}, // will be attached to document directly
   "nested.field.helper": function B(){}, // will be attached to document.nested.helper
   "nested.arrayElements.$.helper: function C(){} // will be attached to element.helper for all elements in .arrayElements
})

// _helpers.nestedHelper is

{
   // note: rootHelper is not nested
   nested: {
      field: { helper: function(){} },
      array: { $: { helper: function() {}
   }
}
