无效的文档参考。文档引用必须具有偶数个段,但是用户具有1'

时间:2020-09-08 17:39:18

标签: ios swift firebase google-cloud-firestore swiftui

我正在将Firestore与SwiftUI结合使用,我尝试进行一个简单的查询以从子集合中获取文档:

struct MyCardsView: View {
    
    @State var myCards = [MyCard]()
    
    @State var show: Bool = false
    @State var selectedId: String = ""
    
    var body: some View {
        
        VStack {
            
            List(self.myCards){i in
                
                Button(action: {
                    
                    self.selectedId = i.card_id
                    self.show.toggle()
                    
                    
                }) {
                    
                    MyCardCell(cardId: i.card_id)
                }
                
            }
            
        }
        .onAppear {
            let db = Firestore.firestore()
            if let uid = Auth.auth().currentUser?.uid {
                db.collection("Users").document(uid).collection("Fiches").order(by: "date", descending: true).addSnapshotListener { (snap, err) in
                    
                    guard let documents = snap?.documents else {
                        print("No documents")
                        return
                    }
                    
                    self.myCards = documents.compactMap({ (queryDocumentSnapshot) -> MyCard? in
                        return try? queryDocumentSnapshot.data(as: MyCard.self)
                    })
                    
                }
            }
        }
        .sheet(isPresented: self.$show){
            CardsView(cardId: self.selectedId)
        }
        
    }
}

此视图一直有效,但是从昨天开始,我收到以下非常奇怪的错误:

由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“ FIRESTORE INTERNAL ASSERTION FAILED:失败,文档引用无效。文档引用必须具有偶数个段,但是用户具有1'

我真的不明白,因为路径正确并且子集合存在...

0 个答案:

没有答案