• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

188
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 ?

almost 3 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.

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda