简体   繁体   中英

How to update a document in firebase firestore using swift?

when i run the following code i get this error.

['FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but User has 1']

func saveLabel(uid: String, label: String){
  
    let userRef = db.collection("User").document(uid)
    
    userRef.updateData(["label": label]) { (error) in
        if error == nil {
            print("updated")
        }else{
            print("not updated")
        }
        
    }

}

This error almost certainly means that uid is empty. You should log it to make sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM