繁体   English   中英

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

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

我正在进行 swift 编程,但每次我运行我的应用程序时,它都会突然开始崩溃。 我收到的错误信息是

线程 1:异常:“FIRESTORE INTERNAL ASSERTION FAILED:无效文档引用。文档引用必须具有偶数段,但 NewGame 有 1”

我搜索了错误,人们说如果我在 db 中有多个 collections 和文档,它往往会发生。 但是我的数据库真的很简单。 只有两个 collections,里面有文件。 就像这张图。 数据库图像

当我点击一个条形按钮时,应用程序崩溃了,这就是这行代码。

@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")
                    }
                }
            }
    }
}

上面的代码在 HomeViewController 中,但我总是在 AppDelegate.swift 文件中出错。

谁能告诉我这里发生了什么以及如何解决这个问题?

问题几乎可以肯定是self.docId在使用时为 nil 或空字符串,这会阻止它为构建 DocumentReference 的代码创建路径段。 我们看不到您是如何分配它的,甚至看不到它的定义位置,因此您必须对其进行调试并弄清楚为什么它没有您期望的值。

暂无
暂无

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

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