简体   繁体   English

Swift - Firestore 文档引用必须具有偶数个段,但

[英]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.这通常发生在userIDwishListName为空时,因为在这种情况下您最终只有 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.

相关问题 无效的文档参考。 文档引用必须有偶数个段,但喜欢有 1 个 - Invalid document reference. Document references must have an even number of segments, but likes has 1 无效的文档参考。 文档引用必须有偶数个段,但用户有 1' - Invalid document reference. Document references must have an even number of segments, but Users has 1' '无效的文档参考。 尝试编辑/删除新条目时,文档引用必须具有偶数段 - 'Invalid document reference. Document references must have an even number of segments' when trying to edit/delete new entry xcode 6.01+ swift:我必须具备的最小项目结构/如何删除不需要的文件引用? - xcode 6.01+ swift: What is the minimal project structure I must have / How to remove unneeded file references? Swift Firestore 获取文档 ID - Swift Firestore Get Document ID 将文档的文档 ID 添加到其自己的 Firestore 文档 - Swift 4 - Add a Document's Document ID to Its Own Firestore Document - Swift 4 从Firestore Swift获取文档ID - Get document id From Firestore Swift 努力通过 Firestore 传递单个文档 - Swift - Struggling to pass a single document through Firestore - Swift 在 Firestore 中收听一个添加的文档 - Swift - Listening to one added document in Firestore - Swift 如果文档存在于 swift 中,如何从 Firestore 中删除它? - How to delete a document from firestore if it exists in swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM