Snapshot.ref is not a function

I am trying to update a field from a snapshot, but even if the snapshot is not null and printed correctly, I cannot use ref.update() on it. I tried to execute this answer . What am I missing here?

My code is:

  ref.limitToLast(1).on('child_added', function(snapshot) { console.log(snapshot.val()); var serial_number = String(snapshot.child("serial").val()); // console.log(serial_number); snapshot.ref().update({ signed: 'true' }); // ... } 

Output:

output

+5
source share
1 answer

The problem is that the answer you refer to uses the previous version of Firebase, and the API is very close to the current version, there are several differences.

There is a guide that discusses the changes and what needs to be done when upgrading from Firebase version 2 and version 3.

In particular, many attributes without arguments have been changed to read-only properties :

front

 // Reference var key = ref.key(); var rootRef = ref.root(); var parentRef = ref.parent(); // Query var queryRef = query.ref(); // DataSnapshot ref.on("value", function(snapshot) { var dataRef = snapshot.ref(); var dataKey = snapshot.key(); }); 

after

 // Reference var key = ref.key; var rootRef = ref.root; var parentRef = ref.parent; // Query var queryRef = query.ref; // DataSnapshot ref.on("value", function(snapshot) { var dataRef = snapshot.ref; var dataKey = snapshot.key; }); 
+12
source

Source: https://habr.com/ru/post/1259363/


All Articles