1

I'm working on a project which needs to select data from Firebase on multiple fields.

I have a firebase database like this:

[{
    date: "2016-01-29"
    done: false
    task: "hello world"
},
{
    date: "2016-01-29"
    done: false
    task: "hello world"
}]

Now I want to query all data with date is today and done is true.

I look around google for a while but there's nothing work. Is there any one can please help me to figure this out?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Trung Bui
  • 188
  • 1
  • 2
  • 13

1 Answers1

1

You can only query on a single property with Firebase queries. So either you'll have to do the rest of the filtering client-side or you'll have to combine the values into a single 'date_done' property.

[{
    date: "2016-01-29",
    done: false,
    date_done: "2016-01-29_false",
    task: "hello world1"
},
{
    date: "2016-01-29",
    done: false,
    date_done: "2016-01-29_false",
    task: "hello world"
}]

Now you can get all the queries that were done on January 29 with:

ref.orderByChild('date_done').equalTo('2016-01-29_true').on(...

For some more information from people who asked similar questions, see:

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks Frank a lot. I figure out what need to do with the issues. I have to redesign my database and add some fields for further purpose. – Trung Bui Jan 18 '16 at 03:35