Recover firebase data with multiple parameters

Asked

Viewed 696 times

5

I’m trying to recover a firebase node, but this one needs to meet two parameters, start date and end date. The knot stays the way they passed me an option would be to put one more value to date_start_end : 1478484000_1478397600, but with that you can not search between the dates. This would not be a viable option.

inserir a descrição da imagem aqui

I also had trying to use only that firebase does not support more than one orderby

.orderByChild("date_start").startAt(mDay).endAt(mDay) .orderByChild("date_end").startAt(mDay).endAt(mDay);

this leads to the error of

java.lang.IllegalArgumentException: You can't combine multiple orderBy calls!

Any suggestions to resolve this issue?

1 answer

1

Of documentation :

You can only use one order-by method at a time. Calling an order-by method Multiple times in the same query throws an error.

So that’s why you have a mistake.

There may be a problem with how you structured this query, because you want to filter records that started between mDay and mDay and all who ended in mDay and mDay. What do you need ? see everyone who started and finished on the same day ?

Wouldn’t it be better to search for records that started between one date and another and display the date they ended ? Or list everyone who ended up between one date and another and list when they started ?

Something like : .orderByChild("date_start").startAt(07112016).endAt(07122016); ( I don’t know how you’re arranging this date)

  • the date is timestamp, my intention would be to fetch the records that are between the start (date_start ) and end (date_end) dates myDay corresponds to the timestamp of the day. The query I need to mount would be to resolve the following situation: Pick one or n record that are between the start date and the end date, based on the current date. In sql would look something like this: SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d') &#xA; FROM users &#xA; WHERE signup_date >= CURDATE() && signup_date < (CURDATE() + INTERVAL 1 DAY)

  • So in case you have a single "signup_date" field and are filtering using it. Then the logic is signup_date > data atual && signup_date < data limite right ? Turning to Firebase would be something like .orderByChild("signup_date").startAt(dataAtual).endAt(dataLimite);

  • I understood what you put there, and the code you made makes total sense. But when I have to compare among the children as in the example of the question. Compares the date between the child node date_start and the child node date_end relative to the current day<myDay>. This would be possible?

  • In Firebase, it is not possible to search for two "Keys", I believe that if you want to do a search in the two Childs, you will have to do programmatically (Doing a query, and then filtering this query with the other data) or create an index that combines the two, the problem is that because it comes to dates I think it will not serve your purpose.

  • vlw by help, will not really help me, the purpose of this would be to reduce the amount of items to be recovered from the server (firebase) side. Unfortunately I will have to search everything and filter when showing, but vlw the force.

  • @Jeffersonrodriguesdossantos, for nothing, I know that using Firebase with Javascript you can do a query in the return of the other, I do not know if on Android is possible, if you want to give one look at

  • Depending on the application if it is going to run in angular 2 David East made a library for this, unfortunately there is no ara java or Swift da uma olhada la ai ta bem legal. [https://github.com/davideast/Querybase]

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.