使用Meteor删除Mongo集合中的所有内容

时间:2015-02-01 03:20:40

标签: mongodb 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
    }
  });
} 

1 个答案:

答案 0 :(得分:1)

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

解决方案是在服务器上定义Meteor method,删除任务,然后从客户端调用它。

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

相关问题