I am new to firebase and trying to add a user to a chat group on login. My function currently appends the user to 'members' by using childbyautoid but this adds a firebase generated ID key and key titled uid.
What I want to do is generate the next number in the sequence as the key, and the user id as the value.
My function in Swift:
let key = self.databaseRef.child("groups").child("-LEf3_zagKHB6qQEbTL7").child("members").childByAutoId().key
let newuser = ["uid": uid]
let childUpdates = ["/members/\(key)": newuser]
self.databaseRef.child("groups").child("-LEf3_zagKHB6qQEbTL7").updateChildValues(childUpdates)
When I try to add a fourth member to the group, this is what I get in Firebase for the group "LEf3_zagKHB6qQEbTL7"...
{
"description" : "The Tribe",
"members" : {
"0" : "5pw4MkVxKob8nXiHojTl61tQQ822",
"1" : "FeP6H8H0PyVjMDcqwH3zbY0xAxg2",
"2" : "ZtcfskmMydQmGIarYyKiuO6cKbh1",
"-BdfJitm1T_fu1ssXcUY" : {
"uid" : "dSiUpZfdRpXxE7WQL01T5lOUkfF2"
}
},
"title" : "popupzendo"
}
What I am expecting to see is this...
{
"description" : "The Tribe",
"members" : {
"0" : "5pw4MkVxKob8nXiHojTl61tQQ822",
"1" : "FeP6H8H0PyVjMDcqwH3zbY0xAxg2",
"2" : "ZtcfskmMydQmGIarYyKiuO6cKbh1",
"3" : "dSiUpZfdRpXxE7WQL01T5lOUkfF2"
}
},
"title" : "popupzendo"
}