简体   繁体   English

FIRInvalidArgumentException,原因:文档路径不能为空

[英]FIRInvalidArgumentException, reason: Document path cannot be empty

I am trying to access some values in a dictionary I made from Firebase snapshot, I use these values to access some document in my firestore, but these values come back empty therefore the path I used those values in, is empty, and I can't access the firestore.我正在尝试访问我从 Firebase 快照创建的字典中的一些值,我使用这些值来访问我的 firestore 中的一些文档,但是这些值返回为空,因此我使用这些值的路径是空的,我可以t 访问 Firestore。

I am not sure if the values are nested in the dictionary, I tried searching for accessing nested dictionary, but I got other errors.我不确定这些值是否嵌套在字典中,我尝试搜索访问嵌套字典,但出现其他错误。

Here is the output这是 output

snapshot Optional({
16640500463403668 =     {
    ReciverID = "manarx224@gmail.com";
    RewardKey = "Reward_25";
    isScanned = 1;
};
}) 
Scanned successfully 
16640500463403668 
Dictionary is:
Optional({ 16640500463403668 = { ReciverID = "manarx224@gmail.com"; RewardKey = "Reward_25"; isScanned = 1; }; }) 
resciver id is
RewardKey id is

2022-09-25 02:31:20.924590+0300 KhutaaScannser[30891:1892245] *** Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Document path cannot be empty.'

And here is my code:这是我的代码:

let ref = ref.child("AllQRCodes")
ref.getData { [self] (error, snapshot) in
    print("snapshot \(snapshot.value as Any)")
   
    if let value = snapshot.value as? [String: Any] {
        for key in value.keys {

            if key == QRnumber {
        
                self.ref.child("AllQRCodes").child(QRnumber).child("isScanned").setValue(true)
                print("Scanned successfully")
                self.messageLabel.text = "Succefully Scanned"
                print(key)
                
                let dictionary = snapshot.value as? NSDictionary
                print("Dictionary is:  " )
                print(dictionary)
                
                var ReciverID = dictionary?["ReciverID"] as? String ?? ""
                var RewardKey = dictionary?["RewardKey"] as? String ?? ""
                
                print("resciver id is" + ReciverID)
                print("RewardKey is "+RewardKey)
                
                db.collection("users").document(ReciverID).collection("UserRewards").document(RewardKey).setData( ["isScanned": true], merge: true)
                
                print("Scanned successfully")
                self.messageLabel.text = "Succefully Scanned"

                self.ref.child("AllQRCodes").child(QRnumber).removeValue()
                
                break

You're not reading from the correct child snapshot.您没有从正确的子快照中读取。

var ReciverID = dictionary?["QRnumber"]["ReciverID"] as? String ?? ""

You might need some extra null handling in there, so if you get an error about that, please search for the error message.您可能需要在其中进行一些额外的 null 处理,因此如果您收到关于此的错误,请搜索错误消息。

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

相关问题 iOS Firestore '文档路径不能为空' - iOS Firestore 'Document path cannot be empty' 抓紧修复 firebase“文档路径不能为空” - do catch to fix firebase "document path cannot be empty" 文档路径必须是非空字符串,Flutter - Firebase错误? - A document path must be a non-empty string, Flutter - Firebase error? FirebaseError:无法使用空路径调用 Function CollectionReference.doc() - FirebaseError: Function CollectionReference.doc() cannot be called with an empty path Uncaught (in promise) FirebaseError: Function collection() cannot be called with an empty path - Uncaught (in promise) FirebaseError: Function collection() cannot be called with an empty path Flutter firebase firestore:'path.isNotEmpty':文档路径必须是非空字符串) - Flutter firebase firestore: 'path.isNotEmpty': a document path must be a non-empty string) 更新数据时 Swift Firebase 'FIRInvalidArgumentException' - Swift Firebase 'FIRInvalidArgumentException' when updating data 如何检查 Firestore 中的文档是否为空? - How to check if a document is empty in Firestore? 属性 servicetoken 不能为空 - property servicetoken cannot be empty DynamoDB Map/Document扫描时为空,但在表中不为空 - DynamoDB Map/Document is empty when scanned, but is not empty in the table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM