Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only changed value on Firebase Database?

How to get only changed value on Firebase Database? Because every time I changed a value on dir, ex:

/ some_user
 ~ id
 ~ name
 / data
   ~ order_id
   ~ order_name <<= Changed in here

But when I get the changed data, I get all the tree structure and not only changed data order_name. So I just wanted it to return something like this:

/ some_user
     / data
       ~ order_name <<= Specific changed data

So I can identify what is the exact key data that has changed. How can I do this? Thanks.

like image 690
Muhamad Yulianto Avatar asked Oct 06 '16 08:10

Muhamad Yulianto


1 Answers

Attach the listener to the order_name reference.

var user = "Alan";
var ref = firebase.database().ref(user + "/data/order_name");

ref.on("value", function(snapshot) {
    console.log(snapshot.val());
});
like image 171
Himani Agrawal Avatar answered Sep 27 '22 22:09

Himani Agrawal