We have a data set that has grown to 15000 records and has become very difficult to manage. The data set needs re-imported weekly in entirety, so we have to clear out the date set first.
First off WIX REALLY REALLY needs a delete all records function for a collection or an option to replace all on import. This would save countless hours of aggrevation!
So previously, I have been going to manage the collection and using a UI trick to delete 1000 records at a time. Not sure what changed, but this no longer works as it just times out.
I found a number of posts offering scripts to delete all records, so I implemented a recursive version of those since these other scripts can only delete 1000 records at a time. But whenever I run this, I get the following error.
Uncaught (in promise) Error: The current user does not have permissions to remove on the AllStateMasterAdditionalFilter collection.
I have the collection on the page set to read-write, have the permissions set on the collection for delete to Admin, and have the page set up as a Members only page. I have tried logged in as Admin and Site Owner with the same results. Nothing gets deleted.
import wixData from 'wix-data';
$w.onReady(function () {
});
export function DeleteMaster_click(event) {
	console.log("Deleting all records");
	deleteDataRecursive("AllStateMasterAdditionalFilter", 0);
}
function deleteDataRecursive (collectionName, recordCount) {
	wixData.query(collectionName)
		.limit(100)
		.find()
		.then((result) => {
			var pageRecordCount = result.items.length;
			console.log('Deleting ' + pageRecordCount + ' records');
			var recordsProcessed = 0;
			for (var i = 0; i < result.items.length; i++){
				if (result.items[i] === null) continue;
				var item = result.items[i];
				wixData.remove(collectionName, item._id)
					.then((removeResult) => {
						recordsProcessed ++;
						if ((recordCount + recordsProcessed) % 10 === 0) {
							console.log('Deleted record count: ' + (recordCount + recordsProcessed));
						}
					})
			}
			recordCount += pageRecordCount;
			if (pageRecordCount > 0) {
				deleteDataRecursive(collectionName, recordCount);
			}
			else {
				console.log('delete data done.' + recordCount + ' records removed.' );
			}
		})
		.catch((err) => 
		{
			console.log ('query error:' + err);
			deleteDataRecursive(collectionName, recordCount);
		});
}