VinsonG
VinsonG

Reputation: 25

Drop all things in a Mongo collection with Meteor

I am new to meteor.js and MongoDB. I can't figure it out how to delete all objects that I previously inserted into the Mongo collection Object. The method in meteor doc is not working for me.Tasks.remove({}); not working.

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
    Template.myInsertButton.events({
    'click a': function () { 
        Tasks.insert({
            text: num,
            createdAt: new Date() // current time
        });

    }
  }); 
  Template.myResetButton.events({
    'click a': function () {
        Tasks.remove({});   // NOT WORKING HERE
    }
  });
} 

Upvotes: 0

Views: 302

Answers (1)

Dan Dascalescu
Dan Dascalescu

Reputation: 152056

For security reasons, you can't update or remove more than one object at a time from the client.

The solution is to define a Meteor method on the server that removes the tasks, then call it from the client.

Alternatively, you can remove tasks one by one from the client, but this is less efficient.

Upvotes: 1

Related Questions