“失败的FIRSTORE INTERNAL ASSERTION FAILED:无效的文档引用文档引用必须具有偶数个段,但是NewGame包含1个段”

问题描述

我正在快速编程,但是每次运行应用程序时,它突然开始崩溃。 我收到的错误消息是

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

搜索错误,人们说我在db中有多个集合和文档,这很可能会发生。但是我的数据库非常简单。只有两个馆藏,里面有文件。喜欢这张图片

db image

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

@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的代码创建路径段。我们看不到您如何分配它,甚至看不到它的定义位置,因此您必须调试它并弄清楚为什么它没有您期望的值。