简体   繁体   English

“FIRESTORE 内部断言失败:文档引用无效。文档引用必须有偶数个段,但 NewGame 有 1 个”

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

I'm working on swift programming but every time I run my app, it suddenly starts crashing.我正在进行 swift 编程,但每次我运行我的应用程序时,它都会突然开始崩溃。 The error message I got was我收到的错误信息是

Thread 1: Exception: "FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but NewGame has 1"线程 1:异常:“FIRESTORE INTERNAL ASSERTION FAILED:无效文档引用。文档引用必须具有偶数段,但 NewGame 有 1”

I searched the error and people are saying if I have several collections and documents in db, it tends to happen.我搜索了错误,人们说如果我在 db 中有多个 collections 和文档,它往往会发生。 But my db is really simple.但是我的数据库真的很简单。 only two collections and inside of them I have documents.只有两个 collections,里面有文件。 Like this image.就像这张图。 数据库图像

When I tap a bar button, the app crashes, which is this lines of code.当我点击一个条形按钮时,应用程序崩溃了,这就是这行代码。

@IBAction func addPressed(_ sender: UIBarButtonItem) {
    
    performSegue(withIdentifier: K.homeToGameScreen, sender: self)
    
    // create new game array in db & player's ready status -> true
    
    db.collection(K.FStore.newGameCollection)
        .addDocument(data: [K.FStore.gameBoardField: GameBoard.gameBoard, K.FStore.player1Field: playerInfo[K.FStore.nameField]!, K.FStore.player2Field: K.FStore.player2Field, K.FStore.uID: playerInfo[K.FStore.uID]!]) { (err) in
            
            if let err = err {
                print("Error getting documents3: \(err)")
            } else {
                
                self.db.collection(K.FStore.playersCollection).document(self.docId).updateData([K.FStore.isReadyField: true]){ err in
                    if let err = err {
                        print("Error updating player's isReady status: \(err)")
                    } else {
                        print("Document successfully updated")
                    }
                }
            }
    }
}

the code above are in something called HomeViewController, but I always get error in AppDelegate.swift file.上面的代码在 HomeViewController 中,但我总是在 AppDelegate.swift 文件中出错。

Could anyone please tell me what is going on here and how to fix this please?谁能告诉我这里发生了什么以及如何解决这个问题?

The problem is almost certainly that self.docId is nil or empty string at the time it's being used, which prevents it from creating a path segment for the code that's building the DocumentReference.问题几乎可以肯定是self.docId在使用时为 nil 或空字符串,这会阻止它为构建 DocumentReference 的代码创建路径段。 We can't see how you assigned it or even where it's defined, so you'll have to debug this and figure out why it doesn't have the value you expect.我们看不到您是如何分配它的,甚至看不到它的定义位置,因此您必须对其进行调试并弄清楚为什么它没有您期望的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 主题 1:FIRESTORE 内部断言失败:文档参考无效。 文档引用必须有偶数个段,但 Posts 有 1 个? - Thread 1: FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but Posts has 1? 无效的文档参考。 文档引用必须有偶数个段,但喜欢有 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' 我得到无效的文档参考。 文档引用必须在 xcode 中有偶数段错误 - Im getting Invalid document reference. Document references must have an even number of segments error in xcode '无效的文档参考。 尝试编辑/删除新条目时,文档引用必须具有偶数段 - 'Invalid document reference. Document references must have an even number of segments' when trying to edit/delete new entry Swift - Firestore 文档引用必须具有偶数个段,但 - Swift - Firestore Document references must have an even number of segments, but NSInternalInconsistencyException',原因:'FIRESTORE 内部断言失败 - NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED 无效的文档参考 - Invalid document reference Swift Firestore 中带有文档参考的嵌套结构 - Nested Struct with Document Reference in Swift Firestore 如何初始化 Firestore 文档参考 Swift - How to Initialize Firestore Document Reference Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM