0

I am trying to allow users to delete arrays from Firebase Cloud Firestore.

Users can populate their own data by creating arrays such as:

djh38972m1d38f
   0: djh38972m1d38f
   1: Hawaiian Pizza
   2: Ham, Cheese and Pineapple
   3: $18.00

I populate this data into an array at runtime, and can reference this data quite easily, allowing users to select specific entries they wish to edit/delete.

The problem is that I do not know how to remove the array name. I am using this:

DocumentReference documentReference = Firestore.instance.collection('food').document('menu_list');
documentReference.updateData({
  menuItemsArray[selectedMenuItem][0]: FieldValue.arrayRemove([menuItemsArray[selectedMenuItem][0], menuItemsArray[selectedMenuItem][1],
    menuItemsArray[selectedMenuItem][2], menuItemsArray[selectedMenuItem][3]),
});

Where menuItemsArray is the array containing all my user array data and selectedMenuItem is the currently selected index from the menuItemsArray.

The result is that it successfully clears out all the data from inside the array in firebase but I do not know how to remove the actual array reference, or whatever it is called. It leaves me with:

djh38972m1d38f

And then nothing inside it. Is there a way I can remove this too?

Bisclavret
  • 1,327
  • 9
  • 37
  • 65

0 Answers0