I have a list of documents I retrieve from a web API. All documents in this list have the same structure and 2 fields combined create a natural key.
I take this list and persist into a collection.
A month of so later I will call for a fresh subset of documents from the API based on a specifically value from one of the 2 fields. However, not all of the documents in the new subset include all the documents previously persisted.
I need to identify and remove old documents not in the fresh subset.
In SQL this is:
delete a from olderset a
left join newersubset b
on a.f1 = b.f1
and a.f2 = b.f2
where a.f2 is null
-- or something like that
Think of f1 as companyName and f2 as transactionID. olderset
will contain a collection of different companyName/s.
But my newer API call is only getting the transactions of one specific company.
In mongoose, what is the best strategy to remove the company specific older transactions from the olderset
collection. When the documents to be removed do not exists in the newersubset
list?
Can you offer a code example?
via user2367083
No comments:
Post a Comment