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

标签 ios swift firebase firebase-realtime-database

我尝试使用 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" : "Papa 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" : "Papa 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" : {
              "Posts" : {
                "postid01" : {
                  "fjsldkfj" : "nombre",
                  "texzto" : "fksdjh"
                }
              },
              "name" : "Papa 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("PAILA :(")
    }
    })

最佳答案

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

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

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

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

相关文章:

iOS - 私有(private) API - 接听来电

ios - 将数据加载到类中并使用它的策略

swift - 我的打字习惯应该如何 swift 改变?

Swift - 开启元类型

ios - AS3如何使用类绘制矩形

ios - Swift 正确声明对应于协议(protocol)并具有父类(super class)的对象

swift - 为什么将未命名的函数作为转换传递给数组会在最远的抽象中为 Playground 上的迭代计数加一

ios - Swift Firebase -如何阻止电话号码发布到特定引用

swift - 如何在 Swift 上将带有自定义 ID 的文档添加到 Firebase (Firestore)

java - 是否可以在 android firebase 上仅显示特定用户 ID 的数据?