0

I have a Firebase database that I need to retrieve some data from: My database is set up like this:

enter image description here

I wish to pull the value of Addition and plus one. I have been trying with transaction but that was resulting in countless errors so I gave up on that and tried pulling it then updating it, but I was getting the value of undefined when I console logged it.

My code:

var numbere;
var cb= "Addition";
    firebase.database().ref(UserIDKey+cb).once('value').then(function(snapshot) {
   numbere = snapshot.val().numbere;

});
console.log(numbere);

Any help would be great I have spent many hours trying to get this to work. (I am not very good at Firebase).This is for a school assignment and this is the last thing I need in order for it to work. Thanks in advance.

hamish
  • 69
  • 1
  • 6
  • Possibly helpful: http://stackoverflow.com/questions/43442796/get-a-value-from-firebase-and-update-it-with-the-current-value-1/43444317#43444317 –  Apr 17 '17 at 11:19
  • `firebase.database().ref(UserIdKey+cb+"/numbere").transaction(numbere => numbere + 1)`. –  Apr 17 '17 at 11:20
  • Move the console.log statement inside the brackets. So immediately following the number = snapshot line increment numbere and then output to log - remember all of that goes inside the brackets. – Jay Apr 18 '17 at 17:43

0 Answers0