Firebase-js-sdk: [Firestore] Offset missing in the client-side SDK

Created on 1 Feb 2018  路  7Comments  路  Source: firebase/firebase-js-sdk

Describe the problem

Relevant Code:

firestore.collection("articles")
                .limit(20)
                .offset(20)
                .get()

Is there a reason offset is not available for the client-side SDK?

thanks.

firestore

Most helpful comment

@samtstern Firebase should prioritize this and fix both, adding offset to web SDK and the offset billing issue. Any database technology without skip or offset is useless because there is not a reliable way to implement the pagination. Pagination cannot be done using cursors because you could end up with gaps between pages.

Please let us know. My team is in the research phase to see which backend technology we are going to use. Thanks

All 7 comments

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@theiliad good question. There is no offset() on mobile because it does not interact well with offline caching and latency compensation for write operations. The server SDKs don't have any offline data so they can support operations like offset() and select().

@samtstern Should be a way to add it for the web SDK and throw errors if used with offline data.

Not being able to paginate using offset will cause many to setup a backend even in cases where they don't need one, and paginating using orderBy() and startAt() will cause you to not be able to use another orderBy() (because of the 1 orderBy limit)...

@theiliad that's reasonable, but for now we are prioritizing feature parity across Android/Web/iOS where possible since so many developers are building cross-platform apps.

Even where we support offset() we intend for usage to be rare. It does not have very attractive billing properties:

"However, when you send a query that includes an offset, you are charged a read for each skipped document. For example, if your query uses an offset of 10, and the query returns 1 document, you are charged for 11 reads. Because of this additional cost, you should use cursors instead of offsets whenever possible." (source)

@samtstern Firebase should prioritize this and fix both, adding offset to web SDK and the offset billing issue. Any database technology without skip or offset is useless because there is not a reliable way to implement the pagination. Pagination cannot be done using cursors because you could end up with gaps between pages.

Please let us know. My team is in the research phase to see which backend technology we are going to use. Thanks

@yankooknay offset() is not likely to come to the mobile SDKs for a long time, nor is it something that will become more price or performance efficient in the server SDKs any time soon. If native offset is a critical feature for your app then Cloud Firestore is probably not the right database for you.

Was this page helpful?
0 / 5 - 0 ratings