4

I have a Firebase that looks like this:

{
  "jobs" : {
    "-Jnbc60FQGiKUubz0u6e" : {
      "Description" : "The sink has a leaky faucet!",
      "uid" : "simplelogin:4"
    },
    "-Jnbc60FQGiKUubz0u6e" : {
      "Description" : "The microwave is broken",
      "uid" : "simplelogin:6"
    },
    "-Jnbc60FQGiKUubz0u6e" : {
      "Description" : "Window Cracked",
      "uid" : "simplelogin:6"
    },
  }
}

I'm trying to understand querying in Firebase but am getting really confused.

What I want to do is the equivalent of this SQL query:

SELECT * FROM jobs WHERE uid="simplelogin:6"

Here is where i'm at in Angular:

var firebase = new Firebase(firebaseURL);
var jobs = firebase.child('jobs');

// BIND FIREBASE DATA TO LOCAL VARIALBES FOR 3 WAY DATA BINDING
$firebaseObject(jobs).$bindTo($scope, 'Jobs');

That pulls in all of the jobs which I can access, but I need to filter it somehow, and then bind that variable to the $scope.Jobs variable.

How would that be accomplished?

1

1 Answer 1

6

I have some suggestions:

So, you can accomplish your goal by combining .orderByChild() and .equalTo() like so:

var firebaseRef = new Firebase(firebaseURL);

var userId = "simplelogin:6";
var jobs = firebaseRef.child("jobs").orderByChild("uid").equalTo(userId);

var jobsObject = $firebaseObject(jobs);
jobsObject.$bindTo($scope, "jobs").then(function(){
  console.log("jobsObject bound to $scope.jobs");
});
2
  • 1
    I don't understand how orderByChild(userId) filters out to only the userId, where is uid even being referenced?
    – Jordash
    Apr 23, 2015 at 21:37
  • Great! Sorry about the initial confusion.
    – sbolel
    Apr 23, 2015 at 22:00

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.