Skip to content

Instantly share code, notes, and snippets.

Created April 25, 2013 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5456919 to your computer and use it in GitHub Desktop.
Save anonymous/5456919 to your computer and use it in GitHub Desktop.
Simple method to remove all the documents from a collection. This adds a new truncate method to the Meteor.Collection prototype. The term "truncate" is taken from a similar TSQL operation "truncate". See http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html
/**
* Removes all documents from the collection
* @example testCollection = new Meteor.Collection('test')
* testCollection.truncate
*/
Meteor.Collection.prototype.truncate = ->
@find().forEach (item) =>
@remove item._id
@russellfeeed
Copy link

Converted to JS using http://js2coffee.org/ - hope you don't mind.

Meteor.Collection.prototype.truncate = function() {
  return this.find().forEach((function(_this) {
    return function(item) {
      return _this.remove(item._id);
    };
  })(this));
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment