hi,
is there a way to delete all the result items of a query from the database?
Just delete them one at a time. Something like
wixData.query(…)
.find()
.then((res ) => {
res.items.forEach(item => {
wixData.remove(…, Item);
})
})
Hi Yoav ,
i followed your code but i cant get the deleting step to work.
let deleteId = $w("#dataset1").getCurrentItem()._id;
wixData.query("COFFEE-TABLE-DROPDOWN")
.eq('coffeeTableName', deleteId)
.find()
.then((res) => {
console.log("query run");
res.items.forEach(item => {
wixData.remove('COFFEE-TABLE-DROPDOWN', item);
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;
});
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
});
}
Is there really no way to delete the matching items of a query in exactly one request?
Something like in SQL, DELETE FROM table_name WHERE condition
The only ways I’ve been able to see is to query the DB and pass modified results into a bulkRemove or remove each individually. This seems extremely unnecessarily inefficient.