Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda