0

I got stuck on querying. I want to query a post based on "Time and Number of Likes" but not figuring out how to query on firebase. Example :

Query mquery =FireBaseDatabase() getReference().getinstance()
.child("post").
orderedbychild("likes").startAt(30)

JSON Structure

post

   fubeukdo8r7yjdjehbdjjd
          message : "hello"
          likes : 40
          timestamp :  4 june 2019

   pcjhuwnd783nhdjhbdhj
          message : "hi there "
          likes : 30
          timestamp :  1 june 2019

   tyjggjkshhx92u79p093
          message : "how r u"
          likes : 25
          timestamp :  2 june 2019

    qeldhkdlje8fhj00jdkjeh
          message : "all is well"
          likes : 20
          timestamp :  1 june 2019

here i want of only todays post with more than 30 likes.....so you have any idea how we can solve this problem on firebase

Vedprakash Wagh
  • 3,595
  • 3
  • 12
  • 33
yuvi1234
  • 25
  • 3

1 Answers1

1

Firebase Database doesn't allow to use multiple clauses to query the data. ie in your case to query by both time and likes. One way to solve this is to combine likes and timestamp and have a new data value and use this to query. You can find more information from this Or if you are using multiple clauses more frequently it's better to use Firestore which supports multiple WHERE clauses to query the database.

sanoJ
  • 2,935
  • 2
  • 8
  • 18