Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda