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

156
Visualizações
Firebase remove specific in a the field

I'm new to react native, I'm trying to delete a specific field but having issue

Firebase

I'm trying to remove cm0IF5KopLgxnJTUtfi403kJuMl2 in the FriendList

Here is my code:

export default function deletefriends(FriendsUID){

    const friendremove = async() =>{

        // get current users uid
        const Uid = firebase.auth().currentUser.uid

        // define the current users 
        const currentUID = firebase.firestore().collection('users').where(
            "UID", "==", firebase.auth().currentUser.uid).get();
           
        // add the other users uid to current users friendlist
        currentUID.then((querySnapshot) => 

        {querySnapshot.forEach((doc) => {doc.ref.update(

            {FriendsList:FriendsUID.delete()})
        })
    })
    

    }

How do I delete the FriendsUID?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Because you are working with a ID map instead of an array, you will need to change out your code to (omitted unrelated parts):

(doc) => {
  const friendsListMap = doc.get('FriendsList');
  delete friendsListMap[uidToDelete];
  return doc.ref.update({ FriendsList: friendsListMap });
}

or

(doc) => {
  return doc.ref.update({
    [`FriendsList.${uidToDelete}`]: firebase.firestore.FieldValue.delete()
  });
}

You should update your code to properly chain the Promises together (some are floating, use querySnapshot.docs.map and Promise.all) and consider making use of a transaction to perform these changes so you can ensure that data isn't wrongly being deleted.

about 4 years ago · Juan Pablo Isaza Relatório

0

If you are trying to remove a single item from the FriendsList array, you need the arrayRemove operation. From the documentation on updating items in an array:

await washingtonRef.update({
    regions: arrayRemove("east_coast")
});
about 4 years ago · Juan Pablo Isaza 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