Delete children using id stored in parent in retool firestore

I have a table in retool that shows user collection from firestore. each user has multiple courses. Each user also has multiple tests. Now once a user is selected, i have a delete button. i want this delete button to delete the tests, courses and then itself. How do i do this? These are test users that i want to delete. Please note i am using firestore for my database

Is it firestore NoSQL database you are using? Then query each collection for the matching documents and get the document ID. Put it in an array and batch delete.

Thank you for your response. Can you help me a little more? how do i do this? do i need to create 3 scripts?

  1. Script of type resource query to get filtered data.
  2. Script of type resource query to delete document and leave document id empty
  3. Script of type query and then in this 3rd script call number 2 passing in array values from 1?

Can you share a sample script if possible?

FYI I am in no way a professional

const userID = table.selectedRow._id;  //get the id of the user 
const filteredData = testsData.filter(obj => obj === userID); //filter out the data

then pass into a resource query the id for each bit of data from your filter data.

setup loops and stuff to repeat this for all the data you need to delete.

To batch delete you would have to use raw mod in the resource query. I haven't actually done this for deleting yet. There are examples of batch updates found in the raw mode, i imagine it is similar.

1 Like