Firebase querying when combining orderByChild star

2019-07-26 23:13发布

I'm trying to set up a firebase query that will implement pagination for me. Similar to this: https://www.firebase.com/blog/2013-10-01-queries-part-one.html#paginate

My problem is when I try to combine the three methods mentioned above. For example, one of my ref's looks like this: userRef = ref.child('Users').orderByChild('email').startAt(null, end.id).limitToFirst(Number(limit))

So I have my Users list. I want it ordered alphabetically by email. I want this new query to start at the last entry of the old query. Lastly I want to limit the amount of children returned to a number like 4.

Now when I combine just two of these methods such as startAt and limitToFirst in other lists, the query works as expected. Unfortunately this depends on the list being presorted in firebase already. What happens with this user query is that firebase just returns the first limit number of children always. It's basically ignoring the startAt part. I've even tried hardcoding in keys to this and it just goes ignored.

I know that you can tell firebase to sort your entries by using indexOn rules and if I have to reconstruct my database I will as a last resort (I implemented the indexOn after I made some users). But I feel like this should be able to work without indexOn, I don't see why it shouldn't.

My data structure is going to look like:

Root:{ 
  Users:{
    01d1d38d-c780-4c5e-8537-a74432dea86e:{
      email:example@gmail.com, 
      questions: {}, 
      comments: {} 
    } 
  }

Is there a way of accomplishing this query properly? Is there a reason why I can't construct a query this way?

0条回答
登录 后发表回答