I want to add a new data on my real time database. However Database deletes old data and write new data. My data scheme like that :
And I want to add a new user on rooms/roomid/users/
My code part :
joinRoom = async (callback = f => f, roomId) => {
currentRoomUid = roomId
var username = ''
await database().ref(`/users/${auth().currentUser.uid}`).once('value', function (snap) {
username = snap.val().username
})
const room = database().ref(`/rooms/${roomId}`);
await room.set({
isStart: true,
currentQuestionIndex: 0
});
const usersRef = database().ref(`/rooms/${roomId}/users`)
usersRef.child(auth().currentUser.uid).set({
username: username,
skor: 0
});
callback(roomId)
}
The important point here is where I add the user. I use the set method. How can I fix it ? I want to add the second user.
The Problem
Old Data
After adding operation