Hi all,
Please help me. This is driving me crazy. I’ve created a backend job to search a database and find all entries that are old than three months. I want it to then update the status of each entry to be Inactive.
What am I doing wrong:
import wixData from ‘wix-data’;
async function Expire() {
// Querying all the items in the collection.
return wixData.query(“DATABASENAME").find().then(results => {
// Declaring a variable for an expiration date to test by initiating it as a date object.
let expirationDate = new Date();
// Setting the expiration date for 3 months prior.
expirationDate.setMonth(expirationDate.getMonth() - 3);
// Using the forEach method to create a filtered array with listings older than 3 months.
let oldListings = results.items.filter(item => item.FieldID < expirationDate);
oldListings.forEach(item => {
let toUpdate = {
“status”: “Inactive”,
};
// Updating each of this items from the collection.
wixData.update(“DATABASENAME", toUpdate);
})
})
}