0

I'm currently struggling to delete an object/field inside a document in firebase. I'm able to delete a collection, or a full document, but not the name/tag fields for a given id. Does anyone know how I can delete the name and tags of a specific object inside the "info" array, for example Object#1 test2 imaged below? Any advice is greatly appreciated. Thank you!


const deleteCard = async (name, tags) => {
    const fieldRef = doc(db, 'labels', activeLabels)
    await updateDoc(fieldRef, {
      info: deleteField({name: name, tags: tags})
    })
    console.log(name, tags)
    getLabels();
  };

Firebase Array

0

1 Answer 1

1

It's not possible to delete an array item knowing only an object field value inside the array with a simple update command. The only way to make changes to an array like this is to read the document, modify the array contents in memory, then update the document field with the modified array.

It would be possible to delete the array item if you knew the entire contents of that array. You could use an arrayRemove operation for that, if you pass an object that is field-for-field equivalent with the item to delete.

See also:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.