Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
How to remove all items of a Mongo collection

I have seen that to remove all items of a Mongo collection using JavaScript I should use :

DockerStats.remove(); //where DockerStats is my collection

So my goal is to purge the DB every 20sec so I did the following code :

  setInterval(Meteor.bindEnvironment(function(){
    DockerStats.remove();
    console.log("ok")
  }),20000);

But when I start the app I had +/- 1000items then despite the terminal wrote 2 times "ok" I still have more than 1000items so it doesn't work because even if I check right after the "ok" I have more than 1000items and the number is always growing up.

So maybe I'm removing the items with the wrong way ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

According to the docs, you need to pass in an empty object to delete the whole collection. So, the below would remove all students from the Students collection:

Students.remove({})

I think this is because if you want to remove everything and start over you would use the drop method and recreate it, which the docs says is more performant.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!