Home > OS >  How to delete a piece of data from an array inside a Nested Collection?
How to delete a piece of data from an array inside a Nested Collection?

Time:11-15

I want to delete an item from an array that is inside a collection that is inside another collection (A nested collection) I have all the data that I need to achieve this, however I do not know how to write I have a slightly idea of how to (I'll be testing stuff on my own, but will leave the question here as well)

I'm using Material UI DataGrid to render my tables and to delete/edit them. I have a piece of information that is saved on my Local Storage in case I required it:

enter image description here

this is how my table looks:

enter image description here

When I select an ITEM and delete it is holding the ID of the item in the data:[Array]

enter image description here

those IDs are the IDs they hold in the data[array] -> :

enter image description here

finally I need to access this document, well I have the following

db.collection("usuarios").doc(user.uid).collection("pedidos").doc(id)

which brings the following:

enter image description here

which means I'm bringing the correct document, however I have no idea how to "update" or delete the array called data[], any ideas? What I want to achieve is that when I press the delete button it will update the array based on the Item selected so if it was Item ID: L-2627 then go through the array inside that collection, get the array called data and delete the item stored in the array.

CodePudding user response:

  1. Read the document into memory.
  2. Modify the array by finding the item and removing it, again from memory.
  3. Write the modified contents back to the document.

There is no shortcut or single operation for doing any this. The fact that the document is in a subcollection doesn't change anything. It's just how you have to modify arrays when you don't know the entire contents of the array item ahead of time.

  • Related