0

I'm trying to delete a single element of an Firestore array. The database has the following structure:

enter image description here

Unfortunately, with the following code nothing happens.

public static void deleteTable(final int pos){
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    FirebaseAuth fAuth = FirebaseAuth.getInstance();

    DocumentReference docRef = db.collection("users").document(fAuth.getUid().toString());
    docRef.update("myTables", FieldValue.arrayRemove(pos));
}

It would be nice if someone could help me out with this one. I just want to delete one element out of the myTables array. (The elements are HashMaps)

Cheers Andi

0

1 Answer 1

1

Firestore does not support modification of array fields by index. FieldValue.arrayRemove() must always be delivered the full contents of the item to remove. In your case, that would be a Map containing all of the nested fields in the item to remove.

If you want to remove a field by index, you have to read the document, modify the array in memory, then write the modified array back to the document.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.