Basic queries in Firebase and AngularJS

I have 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 am trying to understand queries in Firebase but I am really confused.

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

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

This is where I am 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');

      

This goes for all jobs that I can access, but I need to filter them out in some way and then bind that variable to a variable $scope.Jobs

.

How would this be accomplished?

+3


source to share


1 answer


I have some suggestions:



So, you can achieve your goal by combining .orderByChild()

and .equalTo()

like this:

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");
});

      

+5


source







All Articles