Skip to content

Query with startAt / endAt not working? #27

@mikesurowiec

Description

@mikesurowiec

I'm trying to get pagination working in my app, but it appears the startAt / endAt doesn't affect the queries. I'm using it in conjunction with limitToLast, I'm not sure if that's an issue.

I was playing with a couple different strategies, so let me see if I can boil it down...

let myRef = firestack.database.ref('chat-messages/roomId');

myRef.orderByKey().limitToLast(10).once('value').then((snapshot) => {
  let itemKeys = Object.keys(snapshot.val());
  let lastItemKey = itemKeys[itemKeys.length-1];

  myRef.orderByKey().startAt(lastItemKey).on('child_added', (data) => {
    if (data.key === lastItemKey) {
      return;
    }
    // This fires for all items in the collection, despite the startAt(lastItemKey)
    console.log('got data', data);
  });
});

I'm also pretty new to firebase, so there could just be a logical error in there 😄

Thanks for you time!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions