Firestore按行号获取一系列文档 [英] Firestore get a range of documents by row number
问题描述
我在Firestore上有一个非常大的收藏,我希望能够在按参数排序后获得一系列文档,例如:
I have this very big collection on a firestore, and I would like to be able to get a range of documents after sorting by a parameter, for example :
1 doc1
2 doc2
3 doc3
4 doc4
5 doc5
...
我想做一个像 getRangeOfDocuments(start:number,end:number)
这样的服务函数,将其称为 getRangeOfDocuments(2,4)
以获取文档 [doc2,doc3,doc4]
.
I would like to make a service function like getRangeOfDocuments(start: number, end: number)
that would be called getRangeOfDocuments(2, 4)
to get the documents [doc2, doc3, doc4]
.
startAt
和 endAt
运算符将文档作为参数,这意味着要获得先前的结果,我应该使用 doc2
和 doc4
: ref.startAt(doc2).endAt(doc4)
.
The startAt
and endAt
operators are taking documents as parameter, it means that to get the previous result I should have the doc2
and doc4
: ref.startAt(doc2).endAt(doc4)
.
limit
运算符可以使其适用于我想要从 doc1
开始的范围的情况.
The limit
operator can make it work for the case I want to get the range starting at doc1
.
如何使用行号而不是文档来获取不以 doc1
开头的范围?
How can I get ranges not starting at doc1
using row numbers instead of documents ?
推荐答案
Firestore无法将查询偏移结果集中的某个索引.您需要提供一个文档或值,以便从结果集中的某个位置继续查询
Firestore doesn't have the ability to offset a query by some index in the result set. You need to provide a document or value to continue the query from some point in the result set as described in the documentation for pagination. (Think about how the indexes of the results may change over time as new data may have affected the outcome of the query, and you'll see that numeric indexing into results can generate bad results.)
这篇关于Firestore按行号获取一系列文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!