Reputation: 15
Im using firebase realtime database. I have a bunch of users in my ref
let usersRef = db.ref('/users/);
Then I want to detect any changes here with
usersRef.on('value', (snapshot) => {}
This will detect the change but will return all the users, not just the one that has changed a value.
How can I retrieve only the one that has changed in the database?
Thank you and im sorry if it's an amateur question
Upvotes: 1
Views: 462
Reputation: 50830
The listener receives a snapshot that contains the data at the specified location in the database at the time of the event. You can retrieve the data in the snapshot with the val() method.
That technically means any change in users node will return the whole node.
Are you trying to listen to a specific user's node? Then try changing your ref to:
let usersRef = db.ref('/users/userUID')
In case you are showing a list of all users and want to listen for updates for each of them, then you would have to add a new listener for each of them with the above reference. (Just change the UID)
Upvotes: 1