I have a mongoose model called Products which I feed from an external system (a google spreadsheet).
Every time the spreadsheet changes, I get an event and I need to find out what changed and update Products collection accordingly.
The easiest method I though about was:
Product collectionProducts collection again.This is hardly efficient, but it's an easy and clean solution, assuming the collection is not very big and doesn't update too frequently.
Any other method I can think of involves iterating both the updated google spreadsheet and the Products collection and comparing them to each other.
Is there an inherited way of doing this ? perhaps a more efficient algo ?
My suggestion would be to insert into a new empty collection with a temporary name and then rename it to overwrite the existing collection atomically.
You could also consider doing an upsert on each document that has been created or updated in the spreadsheet and then delete any deleted documents.