2

I have an array that looks like this:

validZipCodes = [
  "84606",
  "84605",
  "84601"
]

I'm querying some data like this:

var Jobs = firebase.child('Jobs');

I tried this:

var Jobs = firebase.child('Jobs').orderByChild('ZipCode').equalTo($scope.validZipCodes);

But it returned an error that it was an invalid data-type, is there anyway to say something like:

var Jobs = firebase.child('Jobs').orderByChild('ZipCode').inArray($scope.validZipCodes);

Or something like that.

Note that this is an array comparison & not querying text in an object.

0

2 Answers 2

4

Here is how I eventually did it:

With the foreach command you can easily manipulate data and then push it into an array to re-create a collection of data however you need it.

$scope.validZipCodes = [];
$scope.validContractorJobs = [];

var Jobs = firebase.child('Jobs');

contractorJobs.on('value', function(snap) {
            snap.forEach(function(job) {
                angular.forEach($scope.validZipCodes, function(value, key) {
                    if(job.val().ZipCode == value) {
                        $scope.validContractorJobs.push(job.val());
                    }
                });
            });
        });
Sign up to request clarification or add additional context in comments.

Comments

1

The Firebase .equalTo() documentation states that the value argument should be one of the following types: String, Number, Null, or Boolean.

  • You are getting an invalid data-type error because you are not passing one of these types.

  • There is no method like .inArray() (i.e. querying for equalTo multiple values).

You can review all of the Firebase Query Methods in the Query documentation, which also suggests:

Read our documentation on ordering and querying data for more information and examples.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.