菜鸟教程小白 发表于 2022-12-11 18:34:25

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


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

<pre><code>    {
&#34;districts&#34; : {
    &#34;did01&#34; : {
      &#34;name&#34; : &#34;Teusaquillo&#34;,
      &#34;peopleids&#34; : {
      &#34;stateid01&#34; : true,
      &#34;stateid02&#34; : true,
      &#34;stateid03&#34; : true
      },
      &#34;schools&#34; : {
      &#34;schoolid01&#34; : {
          &#34;location&#34; : &#34;norte 50 grados sur 42 &#34;,
          &#34;name&#34; : &#34;Agustiniano Salitre&#34;,
          &#34;posts&#34; : {
            &#34;eighth&#34; : {
            &#34;nola&#34; : &#34;hola&#34;
            },
            &#34;eighth-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;eleventh&#34; : {
            &#34;name&#34; : &#34;haka&#34;
            },
            &#34;eleventh-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;fifth&#34; : {
            &#34;-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;dsadsad&#34; : {
                &#34;name&#34; : &#34;Hola&#34;
            },
            &#34;dsfsdfdsf&#34; : true
            },
            &#34;first&#34; : {
            &#34;1&#34; : {
                &#34;author&#34; : &#34;Giovanny Piñeros&#34;,
                &#34;text&#34; : &#34;Test&#34;
            },
            &#34;01&#34; : {
                &#34;author&#34; : &#34;Giovanny Piñeros&#34;,
                &#34;text&#34; : &#34;Capo&#34;
            },
            &#34;abdffg&#34; : {
                &#34;author&#34; : &#34;Gio&#34;,
                &#34;text&#34; : &#34;hola&#34;
            },
            &#34;fdgfdg&#34; : {
                &#34;author&#34; : &#34;Giovanny Piñeros&#34;,
                &#34;text&#34; : &#34;Hola&#34;
            },
            &#34;nfdsfds&#34; : {
                &#34;author&#34; : &#34;Giovanny Piñeros&#34;,
                &#34;text&#34; : &#34;Vivir de lo que amo&#34;
            },
            &#34;postid01&#34; : {
                &#34;author&#34; : &#34;Papa frita&#34;,
                &#34;text&#34; : &#34;Hola&#34;,
                &#34;topic&#34; : &#34;Informatics&#34;,
                &#34;year&#34; : &#34;first&#34;
            },
            &#34;rtyrty&#34; : {
                &#34;author&#34; : &#34;Giovanny Piñeros&#34;,
                &#34;text&#34; : &#34;Si con headapp solo sabia manejar strings y colores, imaginate ahora lo que puedo crear&#34;
            },
            &#34;zsadsa&#34; : {
                &#34;author&#34; : &#34;Gio&#34;,
                &#34;text&#34; : &#34;Trest&#34;
            }
            },
            &#34;fourth&#34; : {
            &#34;name&#34; : &#34;hqiq&#34;
            },
            &#34;fourth-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;ninth&#34; : {
            &#34;hola&#34; : &#34;ahah&#34;
            },
            &#34;ninth-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;postid01&#34; : {
            &#34;-KaG0b-X9sWXxXlXlmeK&#34; : &#34;angela&#34;,
            &#34;-KaG0wNu0Gz5oxu4__Ej&#34; : &#34;angela&#34;,
            &#34;author&#34; : &#34;Papa frita&#34;,
            &#34;likes&#34; : {
                &#34;userid01&#34; : &#34;Giovanny Piñeros&#34;
            },
            &#34;text&#34; : &#34;hola&#34;,
            &#34;topic &#34; : &#34;Informatics&#34;,
            &#34;year&#34; : &#34;first&#34;
            },
            &#34;postid02&#34; : {
            &#34;autor&#34; : &#34;Directive&#34;,
            &#34;text&#34; : &#34;Free for the day&#34;,
            &#34;topic&#34; : &#34;General&#34;,
            &#34;year&#34; : &#34;all&#34;
            },
            &#34;second&#34; : {
            &#34;-KaFnTl89keEOx3UpnGJ&#34; : true,
            &#34;-KaFpLsNy6z-TshUJONx&#34; : true,
            &#34;-KaFpMwBdHqBwsq-k6i3&#34; : true,
            &#34;-KaFpz6qwQ2uTevvpxXo&#34; : true,
            &#34;-KaFq21Qdv-Z6KFcu8ZT&#34; : true,
            &#34;-KaFq34fN1-ZxO0EtqEw&#34; : true,
            &#34;-KaFv7a9JvEjPLDDzT8S&#34; : &#34;angela&#34;,
            &#34;-KaFw9Hb6OjIRzeP6jdk&#34; : &#34;angela&#34;,
            &#34;-KaFwAFvFoVEvpzaaVO2&#34; : &#34;angela&#34;,
            &#34;-KaFwAboyWtEOG3NU1yZ&#34; : &#34;angela&#34;,
            &#34;-KaFwAji3rR6e5fCHjFc&#34; : &#34;angela&#34;,
            &#34;-KaFwAmisIA5i4UhvcRw&#34; : &#34;angela&#34;,
            &#34;-KaFyJHEqDzoVoj_zUWI&#34; : &#34;angela&#34;,
            &#34;-KaFy_cqf1mvTxRGN5j_&#34; : &#34;angela&#34;,
            &#34;-KaG-_r4ql2YVc19gbkt&#34; : &#34;angela&#34;,
            &#34;dsfsdf&#34; : {
                &#34;hola&#34; : &#34;dfsad&#34;
            }
            },
            &#34;seventh&#34; : {
            &#34;name&#34; : &#34;dsfhksd&#34;
            },
            &#34;sixth&#34; : {
            &#34;name&#34; : &#34;haaka&#34;
            },
            &#34;tenth&#34; : {
            &#34;name&#34; : &#34;hola&#34;
            },
            &#34;tenth-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;third&#34; : {
            &#34;-KaFnTl89keEOx3UpnGJ&#34; : true,
            &#34;-KaFpLsNy6z-TshUJONx&#34; : true,
            &#34;-KaFpMwBdHqBwsq-k6i3&#34; : true,
            &#34;-KaFpz6qwQ2uTevvpxXo&#34; : true,
            &#34;-KaFq21Qdv-Z6KFcu8ZT&#34; : true,
            &#34;-KaFq34fN1-ZxO0EtqEw&#34; : true,
            &#34;-KaFv7a9JvEjPLDDzT8S&#34; : &#34;angela&#34;,
            &#34;-KaFw9Hb6OjIRzeP6jdk&#34; : &#34;angela&#34;,
            &#34;-KaFwAFvFoVEvpzaaVO2&#34; : &#34;angela&#34;,
            &#34;-KaFwAboyWtEOG3NU1yZ&#34; : &#34;angela&#34;,
            &#34;-KaFwAji3rR6e5fCHjFc&#34; : &#34;angela&#34;,
            &#34;-KaFwAmisIA5i4UhvcRw&#34; : &#34;angela&#34;,
            &#34;-KaFyJHEqDzoVoj_zUWI&#34; : &#34;angela&#34;,
            &#34;-KaFy_cqf1mvTxRGN5j_&#34; : &#34;angela&#34;,
            &#34;-KaG-_r4ql2YVc19gbkt&#34; : &#34;angela&#34;,
            &#34;-KaG0b-X9sWXxXlXlmeK&#34; : &#34;angela&#34;,
            &#34;-KaG0wNu0Gz5oxu4__Ej&#34; : &#34;angela&#34;,
            &#34;-KaG1PA5r7cl70FtBsE4&#34; : &#34;angela&#34;,
            &#34;author&#34; : &#34;hola&#34;
            },
            &#34;twelfth&#34; : {
            &#34;name&#34; : &#34;haoao&#34;
            }
          },
          &#34;users&#34; : {
            &#34;userid01&#34; : {
            &#34;likes&#34; : {
                &#34;postid01&#34; : true
            },
            &#34;name&#34; : &#34;Giovanny Piñeros&#34;,
            &#34;rol&#34; : &#34;student&#34;,
            &#34;stateid&#34; : &#34;stateid01&#34;,
            &#34;year&#34; : &#34;first&#34;
            },
            &#34;userid03&#34; : {
            &#34;Posts&#34; : {
                &#34;postid01&#34; : {
                  &#34;fjsldkfj&#34; : &#34;nombre&#34;,
                  &#34;texzto&#34; : &#34;fksdjh&#34;
                }
            },
            &#34;name&#34; : &#34;Papa frita&#34;,
            &#34;rol&#34; : &#34;teacher&#34;
            }
          }
      }
      }
    },
    &#34;did02&#34; : {
      &#34;name&#34; : &#34;Austin&#34;,
      &#34;peopleids&#34; : {
      &#34;stateid04&#34; : true,
      &#34;stateid05&#34; : true,
      &#34;stateid06&#34; : true
      }
    }
},
&#34;eventos&#34; : {
    &#34;attendiees&#34; : {
      &#34;adshfksafjh&#34; : &#34;giovanny&#34;
    },
    &#34;nombre&#34; : &#34;fiesta&#34;
},
&#34;queue&#34; : {
    &#34;specs&#34; : {
      &#34;specstest&#34; : 0
    },
    &#34;tasks&#34; : {
      &#34;ido&#34; : {
      &#34;_error_details&#34; : {
          &#34;error&#34; : &#34;Task was malformed&#34;,
          &#34;error_stack&#34; : &#34;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)&#34;,
          &#34;original_task&#34; : 0
      },
      &#34;_state&#34; : &#34;error&#34;,
      &#34;_state_changed&#34; : 1482958978549
      }
    }
},
&#34;usuarios&#34; : {
    &#34;hvlksdj&#34; : {
      &#34;edad&#34; : 26,
      &#34;nombre&#34; : &#34;giovanny&#34;
    }
}
}
</code></pre>

<p>如您所见,子节点 <code>postid01</code> 和 <code>second</code> 已更新,创建了一个新子节点,但对于其他位置,这不会发生。</p>

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

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

ref.updateChildValues(dict, withCompletionBlock: {(Error,FIRDatabaseReference) in
    if(Error == nil){
    print(&#34;EXITO :)&#34;)
    }else{
    print(&#34;PAILA :(&#34;)
    }
    })
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我刚刚发现了错误,太简单了,我在字典上弄错了。没有更新的位置是这样写的:</p>

<pre><code>&#34;districts/did01/schools/schoolid01/posts/fourth\(newKey)&#34;: &#34;test&#34;
</code></pre>

<p>如您所见,最后一部分在 newKey 之前缺少一个“/”。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Firebase 中的多路径更新问题具有两个以上的位置,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41605574/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41605574/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Firebase 中的多路径更新问题具有两个以上的位置