Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda