使用 Meteor 将所有东西放入 Mongo 集合中

Drop all things in a Mongo collection with Meteor

我是 meteor.js 和 MongoDB 的新手。 我不知道如何删除我之前插入到 Mongo 集合对象中的所有对象。 meteor doc 中的方法对我不起作用。Tasks.remove({}); 不起作用。

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
    }
  });
} 

出于安全原因,you can't update or remove more than one object at a time from the client

解决方法是在服务端定义一个Meteor method移除任务,然后在客户端调用

或者,您可以从客户端一个一个地删除任务,但这样效率较低。