breaking while loop

Hi,
i have two datasets. dataset 2 filtered by dataset 1. I want to delete all the content in dataset 2 which is referenced to dataset 1 along with the current item in dataset 1.
with my below code it deletes all dataset 2 items successfully as i need, but it also deletes all items from the database collection which dataset 1 is connected to as well.
so i need to stop the loop when dataset 1 is removed.

 	let dataset = $w("#dataset2"); // or the name of your dataset
	dataset.onReady(async() => {
		while (dataset.getCurrentItem()) {
			await dataset.remove();
			console.log("DELETED");
		}
	});
	$w('#dataset1').onReady(async() => {
		while (dataset.remove()) {
			let deleteId = $w("#dataset1").getCurrentItem()._id;
			await wixData.query('COFFEE-TABLE-DROPDOWN')
				.eq('coffeeTableName', deleteId)
				.find() // Run the query
				.then(results => {
					if (results.items.length === 0) {
						console.log("no query result");
						wixData.remove("COFFEE-TABLES", deleteId)
							.then((result) => {
								let item = result; //see item below
								console.log("item deleted");
								$w('#table1').refresh();
								$w("#box18").hide();
							})
							.catch((err) => {
								let errorMsg = err;

							});
						//refresh the table with the updated info

					};
				})
				.catch((err) => {
					let errorMsg = err;
				});

		}
	});
}