0

I have a React application which is using firebase as the back-end. Here is an snapshot of my data structure.enter image description here

The numbers 1001, 1002, 1003 represent the ID of each entry. I'm looking to query this structure and return only the nodes whose city attribute is "Tarzana".

I have been able to grab all of the nodes from firebase and then iterate through them to select and store the ones that match my filter criteria into an array. However, I am almost certain there has to be a more efficient way as I shouldn't have to grab ALL of the data.

Could someone please point me in the direction of how to efficiently query my data with parameters.

1
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase database. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. Commented Jun 9, 2016 at 0:05

1 Answer 1

4

Try this:

Data.orderByChild("city").equalTo("Tarzana");
Sign up to request clarification or add additional context in comments.

3 Comments

Also, I would index the city field if there's a lot of data there.
@MotiAzu What do you mean by index the city field?
You will need a database index on that field if you are going to query by it. Firebase has indexing available through the rules.

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.