Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

382
Visualizações
Firebase React: Remove Item (Map) from array in firestore

I'm trying to remove a map item from an array in firebase. From what I understand with firebase - you are unable to delete the item based on the index. Should I structure this a different way or is there an easier way to remove a specific object from the array? Thank you

Error: 'No document to update: '

enter image description here

  const listingRef = doc(db, 'users', 'savedListings');

  const deleteListing = async () => {
    try {
      await updateDoc(listingRef, {
        savedListings: deleteField()
      });
    } catch (e) {
      console.log(e.message);
    }
  };```
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The doc() takes path to a document that should be users/test@user.com in this case. While you can use arrayRemove() to remove elements from an array field you cannot delete an object from an array unless you know the exact value that object including all the fields.

const listingRef = doc(db, 'users', 'USER_EMAIL'); // USER_EMAIL is document ID

const deleteListing = async () => {
  try {
    await updateDoc(listingRef, {
      savedListings: arrayRemove("THAT_OBJECT")
    });
  } catch (e) {
    console.log(e.message);
  }
};

If you don't have that exact object, then you'll have to read the document, manually remove the element from array and update the document back.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda