So, I have the following firebase structure, whose keys firebase has enumerated, starting at 0. So in the following example the key are numbered 0-3:
"comments" : {
"BAcyDyQwcXX" : [
{
"text" : "Wes. WE should have lunch.",
"user" : "jdaveknox"
},
{
"text" : "#adults",
"user" : "jdaveknox"
},
{
"text" : "@jdtroy yes!",
"user" : "wesbos"
},
{
"text" : " love choccolate!",
"user" : "willowtreemegs"
}
]
}
What I want to do is:
- get the current record count,
- create a new key by incrementing the current record count + 1
- write the new details to the child() index of comments
I have the second and third stage of the process completed,
var commentData = {
text: text,
user: user
};
updates['/comments/' + childindex +'/' + newCommentKey] = commentData;
return firebase.database().ref().update(updates);
I just need to know how to get the current record count. How do I do this?