简体   繁体   English

有没有办法从某个索引中获取 firebase 元素?

[英]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)我有一个按时间戳排序的聊天消息列表,并有一个唯一的 firebase 密钥(由推送操作员制作)

In this list I want to get the message at position 100 from the end without knowing its key.在此列表中,我想在不知道其密钥的情况下从末尾获取位置 100 处的消息。 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.我尝试将过滤方法 limitToLast() 和 limitToFirst 一起使用,这产生了错误,说已经设置了过滤器。

The current way I do it is by downloading all 100 messages with:我目前的做法是下载所有 100 条消息:

    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?有没有一种方法可以让我在不下载所有其他消息的情况下获得第 100 条消息?

Firebase Realtime Database queries don't support specifying an offset, but instead require that you know the key values of the anchor document. Firebase实时数据库查询不支持指定偏移量,而是要求您知道锚文档的键值。 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)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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