How can I delete cretain data from collection when 'expiry date' matches the 'current date' (today)?

I have found the code for remove item from a collection but I am not able to figure out how to do it with my expiry date with upcoming date that matches and item get deleted? Please help

import wixData from 'wix-data';

// ...

let options = {
  "suppressAuth": true,
  "suppressHooks": true
};

wixData.remove("myCollection", "00001", options)
  .then((results) => {
    if(results.items.length > 0) {
      console.log(results.items[0]); //see item below
    } else {
      // handle case where no matching items found
    }
  })
  .catch((err) => {
    console.log(err);
  });

/*  item is:
 *
 *  {
 *    "_id":          "00001",
 *    "_owner":       "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
 *    "_createdDate": "2017-05-24T12:33:18.938Z",
 *    "_updatedDate": "2017-05-24T12:33:18.938Z",
 *    "title":        "Mr.",
 *    "first_name":   "John",
 *    "last_name":    "Doe"
 *  }
 */

Use job scheduler
Take a look at this example: https://youtu.be/oEIY9K3xldg

Example backend function to remove expired items


function removeExpiredItems(){
    const now = new Date()
    wixData.query("myCollection").eq("expiryDate", now).find()
        .then((results) => {
            if (results.items.length > 0) {
                const Items = Item => Item._id;
                // new array with item _id - the items to be removed,
                const ToBeRemoved = results.items.map(Items);

                wixData.bulkRemove("test", ToBeRemoved, {"suppressAuth": true})
            }
        })
    }
        

If you’ve some difficulties in creating scheduling job code, take a look at this:

Thanks alot @workiapps .