Swift - Firestore Document references must have an even number of segments, but

余生长醉 提交于 2020-07-23 07:36:08

问题


Xcode is giving me this error message:

Document references must have an even number of segments, but users/hsiYfWgKz7MVOM77gMPkQYBHYJH2/wishlists has 3'

I have no idea why that error occurs because I thought there are 4 segments with this code:

let wishListName = self.popUpView.popUpTextField.text!

    let db = Firestore.firestore()
    let userID = Auth.auth().currentUser!.uid
    db.collection("users").document(userID).collection("wishlists").document(wishListName).setData(["name": wishListName]) { (error) in
        if error != nil {
            print("Error saving Wishlist")
        }
    }

Note: The document(wishListName) does not exist before. I am trying to auto save it with the specific ID wishListName. Every help ist appreciated :)


回答1:


This typically happens when userID or wishListName is empty, as you end up with only 3 segments in that case.

If you log these values right before the line of code that throws an error, you can find out which one of the two is empty.



来源:https://stackoverflow.com/questions/59330958/swift-firestore-document-references-must-have-an-even-number-of-segments-but

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!