[英]Swift - Firestore Document references must have an even number of segments, but
Xcode is giving me this error message: Xcode 给我这个错误信息:
Document references must have an even number of segments, but users/hsiYfWgKz7MVOM77gMPkQYBHYJH2/wishlists has 3'
文档引用必须有偶数个段,但 users/hsiYfWgKz7MVOM77gMPkQYBHYJH2/wishlists 有 3'
I have no idea why that error occurs because I thought there are 4 segments with this code:我不知道为什么会发生该错误,因为我认为此代码有 4 个段:
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.注意:
document(wishListName)
之前不存在。 I am trying to auto save it with the specific ID wishListName
.我正在尝试使用特定 ID
wishListName
自动保存它。 Every help ist appreciated :)感谢每一个帮助:)
This typically happens when userID
or wishListName
is empty, as you end up with only 3 segments in that case.这通常发生在
userID
或wishListName
为空时,因为在这种情况下您最终只有 3 个段。
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.如果您在抛出错误的代码行之前记录这些值,您可以找出两者中的哪一个是空的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.