This is an old question but no answers found. Old answers' source links are dead, old functions are deprecated.
I've look at these topics (1, 2) amongst others, and also current Firebase guide.
function writeUserData(name, win, loss) {
firebase.database().ref('users/').push({
name: name,
wins: win,
losses: loss
});
}
I need to pull or somehow convert the unique ID from each push to numeric ID: 1, 2
UPDATE:
Here's what I'm trying to do:
- 2 users can login at the same time from 2 different browsers.
- 1st user hits button 'log-in' or 'start' will be written as
users/1/{user's attributes}
on firebase. - if there's an existing user
(somehow I need to check that on the user-end), the next user hits
'start' will be written as
users/2/{user's attributes}
on firebase. Else (no existing user), the user will be written as user1. This is where I think I needpush
instead ofset
. I can useset
to add more users from 1 browser, but if i open the app from another browser/chrome incognito, the app will just reset the existing users. - if a user refreshes or closes the browser, that user will be removed from firebase so another user can log-in.
I've tried different methods (loop, creating new var...) to achieve this.