My collection contains a list of training courses which site members have added to the site via a form. The form populates a collection and this is then displayed in a repeater. I have added a sort by ‘date of course’ which displays the soonest course available first. When the date of the course has passed I would like to archive that course as its already happened. I would like to keep a record of old courses, can the item be moved to an archive collection?
How can I do this automatically?
Hi @roberthodgson44 ,
I recommend adding a filter to the Dataset that gets the course data you display on your site.
Using setFilter() from the Wix-Dataset API you can record the time when the page is loaded, using Date.now() or even a npm package that handles time. Then you can use the filter to only display courses where the Date is greater than the current time.
Within the Data Collections, if you would like to move the old courses to a separate Archive collection, you can use the Job Scheduler to regularly do the following:
-
bulkInsert() whichever courses were filtered out by the filter conditions mentioned above into the Archive Collection
-
bulkRemove() the old courses from the Course Collection
If the main purpose of separating the collections is to keep track of which courses should be displayed, I recommend sticking with a just a Dataset filter.
Even if it is in the same collection, you will always have a way to analyze the data by running queries with filters when you need it. Additionally, this will minimize the amount of work your backend needs to do.
Best of luck!