I'm dealing with a reservation system.ı use firebase realtime database. So I want to remove past data (historically, before today). I decided to use firebase functions for this.I try to use if else (I don't know if there is an easier way) but I couldn't use break and return commands. How can I stop this after deleting the days before today.
database structure : https://prnt.sc/AyubX0SQG3oo
exports.removePrev =
functions.pubsub.schedule("every 5 minutes").onRun((context) => {
const day = new Date();
const targetDateFormat = new Date(day).toLocaleDateString("en-US", {
year: "numeric",
month: "2-digit",
day: "2-digit"});
const resultDay = targetDateFormat.replace(/[/]/g, "-");
admin.database().ref("reservations/").once("value").then((snap)=>{
snap.forEach((days)=>{
if (days.key != resultDay) {
admin.database().ref("reservations/"+days.key).remove();
} else if (days.key==resultDay) {
//Want to break;
}
});
});
return null;
});