Issue
I am trying to create a multi-select delete documents query for a MongoDB database using checkboxes in a table. However, my current query only works for a single row. I need help with creating a query that can delete multiple rows at once.
Resolution
The goal was to create a multi-select delete query for a MongoDB database in Appsmith. The checkbox was added to a table, connected to a simple get documents query. The Appsmith syntax was unknown for deleting multiple rows. Initially, the selectedRow._id
syntax was used to delete a single row, but that didn't work for multiple rows.
A solution was reached using a RAW query. This query uses the map
function along with ObjectId()
to convert the _id
s to the ObjectId
format that MongoDB requires, and was able to delete multiple rows.
{
"delete": "workouts",
"deletes": [ {
"q": { _id: { $in: {{(Table1.selectedRows.map(item => item._id)).map((id) => `ObjectId("${id}")`)}}}},
"limit": 0
} ]
}