• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - Firebase 中的多路径更新问题具有两个以上的位置

[复制链接]
菜鸟教程小白 发表于 2022-12-11 18:34:25 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试使用 Swift SDK 在 Firebase 中一次更新 8 个位置。不知何故,我设法更新了前两个,但其他六个只写入父节点,并且丢失了对应的路径。下面是我的 Firebase 数据库的数据,可以更好地说明这个问题:

    {
  "districts" : {
    "did01" : {
      "name" : "Teusaquillo",
      "peopleids" : {
        "stateid01" : true,
        "stateid02" : true,
        "stateid03" : true
      },
      "schools" : {
        "schoolid01" : {
          "location" : "norte 50 grados sur 42 ",
          "name" : "Agustiniano Salitre",
          "posts" : {
            "eighth" : {
              "nola" : "hola"
            },
            "eighth-KaG1PA5r7cl70FtBsE4" : "angela",
            "eleventh" : {
              "name" : "haka"
            },
            "eleventh-KaG1PA5r7cl70FtBsE4" : "angela",
            "fifth" : {
              "-KaG1PA5r7cl70FtBsE4" : "angela",
              "dsadsad" : {
                "name" : "Hola"
              },
              "dsfsdfdsf" : true
            },
            "first" : {
              "1" : {
                "author" : "Giovanny Piñeros",
                "text" : "Test"
              },
              "01" : {
                "author" : "Giovanny Piñeros",
                "text" : "Capo"
              },
              "abdffg" : {
                "author" : "Gio",
                "text" : "hola"
              },
              "fdgfdg" : {
                "author" : "Giovanny Piñeros",
                "text" : "Hola"
              },
              "nfdsfds" : {
                "author" : "Giovanny Piñeros",
                "text" : "Vivir de lo que amo"
              },
              "postid01" : {
                "author" : "apa frita",
                "text" : "Hola",
                "topic" : "Informatics",
                "year" : "first"
              },
              "rtyrty" : {
                "author" : "Giovanny Piñeros",
                "text" : "Si con headapp solo sabia manejar strings y colores, imaginate ahora lo que puedo crear"
              },
              "zsadsa" : {
                "author" : "Gio",
                "text" : "Trest"
              }
            },
            "fourth" : {
              "name" : "hqiq"
            },
            "fourth-KaG1PA5r7cl70FtBsE4" : "angela",
            "ninth" : {
              "hola" : "ahah"
            },
            "ninth-KaG1PA5r7cl70FtBsE4" : "angela",
            "postid01" : {
              "-KaG0b-X9sWXxXlXlmeK" : "angela",
              "-KaG0wNu0Gz5oxu4__Ej" : "angela",
              "author" : "apa frita",
              "likes" : {
                "userid01" : "Giovanny Piñeros"
              },
              "text" : "hola",
              "topic " : "Informatics",
              "year" : "first"
            },
            "postid02" : {
              "autor" : "Directive",
              "text" : "Free for the day",
              "topic" : "General",
              "year" : "all"
            },
            "second" : {
              "-KaFnTl89keEOx3UpnGJ" : true,
              "-KaFpLsNy6z-TshUJONx" : true,
              "-KaFpMwBdHqBwsq-k6i3" : true,
              "-KaFpz6qwQ2uTevvpxXo" : true,
              "-KaFq21Qdv-Z6KFcu8ZT" : true,
              "-KaFq34fN1-ZxO0EtqEw" : true,
              "-KaFv7a9JvEjPLDDzT8S" : "angela",
              "-KaFw9Hb6OjIRzeP6jdk" : "angela",
              "-KaFwAFvFoVEvpzaaVO2" : "angela",
              "-KaFwAboyWtEOG3NU1yZ" : "angela",
              "-KaFwAji3rR6e5fCHjFc" : "angela",
              "-KaFwAmisIA5i4UhvcRw" : "angela",
              "-KaFyJHEqDzoVoj_zUWI" : "angela",
              "-KaFy_cqf1mvTxRGN5j_" : "angela",
              "-KaG-_r4ql2YVc19gbkt" : "angela",
              "dsfsdf" : {
                "hola" : "dfsad"
              }
            },
            "seventh" : {
              "name" : "dsfhksd"
            },
            "sixth" : {
              "name" : "haaka"
            },
            "tenth" : {
              "name" : "hola"
            },
            "tenth-KaG1PA5r7cl70FtBsE4" : "angela",
            "third" : {
              "-KaFnTl89keEOx3UpnGJ" : true,
              "-KaFpLsNy6z-TshUJONx" : true,
              "-KaFpMwBdHqBwsq-k6i3" : true,
              "-KaFpz6qwQ2uTevvpxXo" : true,
              "-KaFq21Qdv-Z6KFcu8ZT" : true,
              "-KaFq34fN1-ZxO0EtqEw" : true,
              "-KaFv7a9JvEjPLDDzT8S" : "angela",
              "-KaFw9Hb6OjIRzeP6jdk" : "angela",
              "-KaFwAFvFoVEvpzaaVO2" : "angela",
              "-KaFwAboyWtEOG3NU1yZ" : "angela",
              "-KaFwAji3rR6e5fCHjFc" : "angela",
              "-KaFwAmisIA5i4UhvcRw" : "angela",
              "-KaFyJHEqDzoVoj_zUWI" : "angela",
              "-KaFy_cqf1mvTxRGN5j_" : "angela",
              "-KaG-_r4ql2YVc19gbkt" : "angela",
              "-KaG0b-X9sWXxXlXlmeK" : "angela",
              "-KaG0wNu0Gz5oxu4__Ej" : "angela",
              "-KaG1PA5r7cl70FtBsE4" : "angela",
              "author" : "hola"
            },
            "twelfth" : {
              "name" : "haoao"
            }
          },
          "users" : {
            "userid01" : {
              "likes" : {
                "postid01" : true
              },
              "name" : "Giovanny Piñeros",
              "rol" : "student",
              "stateid" : "stateid01",
              "year" : "first"
            },
            "userid03" : {
              "osts" : {
                "postid01" : {
                  "fjsldkfj" : "nombre",
                  "texzto" : "fksdjh"
                }
              },
              "name" : "apa frita",
              "rol" : "teacher"
            }
          }
        }
      }
    },
    "did02" : {
      "name" : "Austin",
      "peopleids" : {
        "stateid04" : true,
        "stateid05" : true,
        "stateid06" : true
      }
    }
  },
  "eventos" : {
    "attendiees" : {
      "adshfksafjh" : "giovanny"
    },
    "nombre" : "fiesta"
  },
  "queue" : {
    "specs" : {
      "specstest" : 0
    },
    "tasks" : {
      "ido" : {
        "_error_details" : {
          "error" : "Task was malformed",
          "error_stack" : "Error: Task was malformed\n    at Object.update (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-queue/dist/lib/queue_worker.js:453:27)\n    at Ih (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:233:395)\n    at R.h.transaction (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:248:466)\n    at /Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-queue/dist/lib/queue_worker.js:446:30\n    at c (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:135:58)\n    at /Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:126:791\n    at Ac (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:63:165)\n    at jf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:126:215)\n    at hf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:125:479)\n    at vf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:231:426)",
          "original_task" : 0
        },
        "_state" : "error",
        "_state_changed" : 1482958978549
      }
    }
  },
  "usuarios" : {
    "hvlksdj" : {
      "edad" : 26,
      "nombre" : "giovanny"
    }
  }
}

如您所见,子节点 postid01second 已更新,创建了一个新子节点,但对于其他位置,这不会发生。

这是我的代码。我根据 Firebase 指南执行了以下操作:

let ref = FIRDatabase.database().reference()
var newPost = ref.childByAutoId()
let newKey = newPost.key  
let dict = ["districts/did01/schools/schoolid01/posts/fifth/\(newKey)" : "test","districts/did01/schools/schoolid01/posts/third/\(newKey)": "test",
                "districts/did01/schools/schoolid01/posts/fourth\(newKey)": "test","districts/did01/schools/schoolid01/posts/postid02\(newKey)": "test",
                "districts/did01/schools/schoolid01/posts/sixth\(newKey)": "test","districts/did01/schools/schoolid01/posts/seventh\(newKey)": "test",
        "districts/did01/schools/schoolid01/posts/eighth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/ninth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/tenth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/eleventh\(newKey)": "test", "districts/did01/schools/schoolid01/posts/postid04\(newKey)" : "test"]

ref.updateChildValues(dict, withCompletionBlock: {(Error,FIRDatabaseReference) in
    if(Error == nil){
    print("EXITO ")
    }else{
    print("AILA ")
    }
    })



Best Answer-推荐答案


我刚刚发现了错误,太简单了,我在字典上弄错了。没有更新的位置是这样写的:

"districts/did01/schools/schoolid01/posts/fourth\(newKey)": "test"

如您所见,最后一部分在 newKey 之前缺少一个“/”。

关于ios - Firebase 中的多路径更新问题具有两个以上的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41605574/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap