firebase database의 pagination이 가지는 한계 - page navigation 불가
Firebase database는 firestore과 realtime database 모두 json과 거의 유사한 형식으로 데이터들을 저장한다.
이때 두 db 모두 우리나라의 많은 커뮤니티에서 흔히 쓰는 방식인 게시글 하단의 숫자를 클릭해서 해당 페이지의 리스트로 넘어가는 방식인 page navigation을 쓸 수가 없다. 오직 현재 페이지에서 다음 페이지/이전 페이지로 이동하는 방식만 가능하다.
Firebase에서는 지정한 key 또는 value 값이 일정한 값 이상/이하일 때만을 걸러줄 수 있기 때문에 만약 글들이 절대 지워지지 않는 환경이라면 각 글마다 id 값을 지정해서 해당 id 값으로 자르면 ( n 페이지는 id = n~n+9인 글을 불러오는 식) 글들을 불러올 수 있겠지만 글 삭제가 가능한 환경이라면 불러와야하는 글들의 id 값을 정하는 것이 불가능해진다.
굳이 이것을 해결하려고 한다면 array를 db에 하나 만들어서 매 페이지의 시작 값을 저장하는 방식이 가능하겠지만, 글이 삭제될 때마다 해당 index 이후의 모든 값을 1씩 증가시켜야하고 복잡한 것들이 많기 때문에 애초에 page navaigation 기능을 쓰고자 한다면 다른 database를 쓰는 것이 좋을 것 같다.
관련 링크
- realtime database
How to implement pagination in firebase realtime database like we can implement in SQL?
I am creating an admin app and it requires to list the products saved in my firebase realtime database. As there can be hundreds of products and they can not be listed on single page so i have to
stackoverflow.com
- firestore
firebase - jump pagination forward and backward with firestore - Stack Overflow
jump pagination forward and backward with firestore
I'm using firestore, and I want to make pagination, you know, for example: case 1: The user is on page 1 and then the user wants to jump to page 10. case 2: The user is on page 10 and then the user
stackoverflow.com