Hi. Trying to bulk remove data from a collection after finding the IDs.
Been scratching my head on this, and I’m sure its a small niggling issue.
Code as below
export function button2_click(event) {
wixData.query("barlocations") //enter collection name here
.limit(1000)
.find()
.then( (results) => {
if(results.items.length > 0) {
let toDeleteArray = [];
let items = results.items;
let length = results.length;
console.log(items);
console.log(length);
for (var i = 0; i < length; i++){
let toDelete = {
"ID": items[i]._id
};
toDeleteArray.push(Object.assign({}, toDelete));
console.log("todelarray" + toDeleteArray[i].ID);
}
wixData.bulkRemove("barlocations", toDeleteArray[i].ID) //here is the problem
.then( (results) => {
console.log("removal done");
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
});
}
});
}
At the wixData.bulkRemove part is the problem in console log which throws up the error Cannot read properties of undefined (reading ‘ID’)
Although the IDs are being registered in the todeletearray, for some reason, it cannot read it?
Hope for anyone’s guidance.
TIA.