2017-01-12 1 views
1

Ich versuche, in Firebase mit dem Swift SDK jeweils 8 Standorte zu aktualisieren. Irgendwie gelang es mir, die ersten beiden zu aktualisieren, aber die anderen sechs schreiben nur an den Vaterknoten und verloren den entsprechenden Pfad. Im Folgenden finden Sie die Daten meiner Firebase DB, die besser die Frage stellt:Multipfad-Update im Firebase-Problem mit mehr als zwei Standorten

{ 
    "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" 
    } 
    } 
} 

Wie Sie aktualisieren sehen kann, werden die untergeordneten Knoten postid01 und second, ein neues Kind, sondern auch für die anderen Standorte zu schaffen, das nicht geschehen.

Hier ist mein Code. Ich habe die folgenden gemäß den Richtlinien 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 :(") 
    } 
    }) 
+0

Sie haben ein Bild des JSON-Baums in Ihre Frage eingefügt. Bitte ersetzen Sie dies durch den tatsächlichen JSON als Text, den Sie einfach erhalten, wenn Sie auf den Link JSON exportieren in [Ihrer Firebase-Datenbankkonsole] klicken (https://console.firebase.google.com/project/_/database/data/). . Da der JSON als Text durchsuchbar ist, können wir ihn einfach verwenden, um mit Ihren tatsächlichen Daten zu testen und sie in unserer Antwort zu verwenden, und im Allgemeinen ist dies nur eine gute Sache. –

+0

@FrankvanPuffelen danke, im Beitrag der JSON –

+0

Danke @FrankvanPuffelen und AL. Für Ihre Hilfe habe ich gerade den Fehler gefunden. –

Antwort

0

Ich habe gerade den Fehler gefunden, es war so einfach, ich mache einen Fehler auf dem Wörterbuch. Die Orte, die nicht aktualisiert wurden, wurden wie folgt geschrieben:

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

Wie Sie der letzte Teil einer „/“ kurz vor dem newKey sehen fehlt.

Verwandte Themen