2 回答
TA贡献1830条经验 获得超9个赞
在 firebase 支持团队的帮助下,我们发现 python 客户端 api 确实存在错误。下一个版本中有一个错误修正。很可能它将使 python 库能够按 documentid 排序,因此使用start_after()
.
到那时你有两种可能的解决方案:
使用另一个字段进行排序和使用
start_after()
将 node.js 库与分页一起使用,例如:
var db = admin.firestore();
admin.firestore().settings({ timestampsInSnapshots: true });
function readNextPage(lastReadDoc) {
let query = db
.collection(collection)
.orderBy(admin.firestore.FieldPath.documentId())
.limit(100);
}
TA贡献1853条经验 获得超9个赞
在我的例子中,我在获取整个集合时遇到了这个错误。它甚至不是那么大的集合,但我猜集合中的文件很大。我做了分页更新。这是一个节点 firebase 函数:
let lastReadDoc = false;
let lastDoc: string = '';
const limitRecordCount = 10;
do {
await db
.collection('something/' + somethingId + '/somethingcollection')
.orderBy('id')
.limit(limitRecordCount)
.startAfter(lastDoc)
.get()
.then((snapshot: any) => {
let counter = 0;
snapshot.docs.forEach((doc: any) => {
const docData = doc.data();
if (lastDoc !== docData.id) {
lastDoc = docData.id;
counter = counter + 1;
}
// ***********************
// business logic per doc here
// ***********************
});
if (counter < limitRecordCount) {
lastReadDoc = true;
}
})
.catch((err: any) => {
lastReadDoc = true;
console.log('Error getting booking documents', err);
});
} while (lastReadDoc === false);
- 2 回答
- 0 关注
- 151 浏览
添加回答
举报