Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!