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

64
Vistas
Remove documents older than x days and other documents referencing it

I'm quite noobish in mongo syntax and wondering how could I achieve this, ideally in JS script:
I want to delete documents in collection A older than let's say 30 days. Not that difficult, but I also want to delete documents in collections B & C referencing them.

Document in collection A:

{ "_id" : ObjectId("58d212eb8a922d458ed5a942"), "updateDate" : ISODate("2017-03-22T06:00:31.337Z") }

Document in collection B:

{ "_id" : ObjectId("60d7bf9246e0fb0006601eee"), "documentA" : "58d212eb8a922d458ed5a942" }

Document in collection C:

{ "_id" : ObjectId("62b9ce0c46e0fb0006de431f"), "documentA" : "58d212eb8a922d458ed5a942" }

As you can see, documents in B and C have a string reference to a document in A.
How could I make a script to delete them with their associated A document older than X days ?
And important note, I'm stuck with Mongo v3.4.2 :)

about 4 years ago · Juan Pablo Isaza
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