How can you delete all values that match a query in a collection?

Hi everyone,

I have been building my Meteor React application but ran into a problem now. I would like to delete all the “fake” generated data I added. But it’s not working.

I have tried several things, from server side deleting (via the console) and via a method. But none of these have worked so far.

So my question: How can you delete all data in a collection that matches a query like this one:

comments.remove({ adminSpark : { $regex: 'false', $options: 'i' }});
–> Not sure if this method is correct.

I am using SimpleSchema + ValidatedMethod.

The complete method looks like this at the moment:

export const emptyDatabase = new ValidatedMethod({
  name: 'AllComments.remove',
  validate: new SimpleSchema({
    event: { type: Boolean }
  run({ event }) {
  comments.remove({ adminSpark : { $regex: 'false', $options: 'i' }});

So what I want to do is delete all the comments in the collection that match adminSpark: false.

To remove several documents in Meteor you must be in a trusted environment, which is always true when your on the server side. Could it be that adminSpark is a boolean field? Then you’d better use comments.remove({ adminSpark: false});

1 Like