簡體   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