I am trying to auto delete collection data after it gets older than 5 days. I used a tutorial by wix but some of their language has changed since then. It doesn’t seem to be working. There are no errors, but nothing is happening.
This is what have for the jsw file
import wixData from 'wix-data';
export function multiply(factor1, factor2) {
return factor1 * factor2;
}
export function clearOldData() {
return wixData.query("College").find().then(result => {
let expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate()-5);
let oldListings = wixData.result.items.filter(item => item._updatedDate < expirationDate);
oldListings.forEach(item => {
wixData.remove("College", item._id);
})
})
}
I am not quite sure if wixData.result.items.filter(item => item._updatedDate < expirationDate); is right.
This is what I have in the job scheduler. Does the time I put means that it runs this job daily?
// /backend/jobs.config
{
"jobs": [ // Define up to 20 different jobs
// Choose one of the options below to define the job execution interval:
// {
// // // Option 1 - define execution interval using a cron expression
// // "functionLocation": "/Autodelete.clearOldData", // Relatively to Backend folder, started by slash
// // "functionName": "clearOldData",
// // "description": "describe your job", // Optional
// // "executionConfig": {
// // "cronExpression": "0 8 * * *" // Set intervals of up to 1 hour
// // // Read about Cron expressions: [https://en.wikipedia.org/wiki/Cron#CRON_expression]
// }
// },
{
// Option 2 - define execution interval by setting time, day of week and day of month
"functionLocation": "/module/Autodelete.jsw", // Relatively to Backend folder, started by slash
"functionName": "clearOldData",
"description": "describe your job",, // Optional
"executionConfig": {
"time": "07:59",
// "hh:mm" 24h format, UTC timezone (e.g. 13:00)
// Optional - uncomment section below for more complex intervals
//"dayOfWeek": "Monday", // Day of week
//"dateInMonth": 1 // Number between 1-31
}
},
{
// Add more jobs. Up to 20 jobs supported.
}
]
}