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 :)