javascript - How to update a specific(nth) child of a key in firebase -
i know firebase has basic query functionality orderby, limitto, startat, endat...., etc. updating has methods update, set. in case have structure this:
so, there list of keys on pin, how can update child pin of specific key javascript?
for example, want update pin of second key. has 20, , want set 30. please, keep in mind list have more 2 keys, maybe later want update child pin of fourth generated key.
how can this?
relative ordering "second" or "fourth" pretty useless here. if want update pin of node key -krno...ho
can with:
firebase.database().ref("pin/`-krno...ho/pin").set(30);
if want update pin of user named cindy, first need query determine key:
firebase.database().ref("pin").orderbychild("name").equalto("cindy").once("value", function(snapshot) { snapshot.foreach(function(user) { user.ref.child("pin").set(30); }); })
the loop in second snippet needed, since there can technically multiple users named cindy.
Comments
Post a Comment