Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Firebase set method not working

Firebase set method not working

Problem

Creating a node app in Firebase, and having a lot of trouble "setting" values. I have a sneaking suspicion this has to do with permissions or something (I haven't set any read/write permissions of my own), but not sure. Simplified code below:

var Firebase = require("firebase");
var Scope = new Firebase('https://my-firebase.firebaseio.com/');

Scope.child("users").child(queue.uid).on('value', function(user) {

    console.log(user.val()); // Works fine
    user.set({id: 123}); // Fails, "Object has no method 'set'"

});

Any ideas would be much appreciated.

Problem courtesy of: Wandering Digital

Solution

The user variable being passed into the value callback is actually a snapshot--not a Firebase ref. So there is no set method.

However, the ref is available on the snapshot by calling .ref():

Scope.child("users").child(queue.uid).on('value', function(user) {
  console.log(user.val()); // Works fine
  user.ref().set({id: 123}); // Yay!
});
Solution courtesy of: Kato

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Firebase set method not working

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×