简体   繁体   中英

Is there a way to get a firebase element from a certain index?

I have a list of chat messages that are ordered by timestamp and have a unique firebase key (made by the push operator)

In this list I want to get the message at position 100 from the end without knowing its key. Is there a way to do this?

I tried using the filtering methods limitToLast() and limitToFirst together which created an error, saying a filter was already set.

The current way I do it is by downloading all 100 messages with:

    admin.database().ref("path/to/messages").limitToLast(100)

And then I look into that list for the first key which is the one I want.

Is ther a way that I can get the 100th message without downloading all the other messages as well?

Firebase Realtime Database queries don't support specifying an offset, but instead require that you know the key values of the anchor document. If you don't know those, you will have to read all documents before/after the one you search for.

Also see:

citiesRef.orderBy("population").startAt(1000000)

来源: 使用查询游标对数据进行分页

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM