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

62
Views
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
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!