【发布时间】:2020-08-05 22:39:59
【问题描述】:
我遇到了这个问题,我无法让 startAfter 处理我在 Firestore 中的数据。 我给出了这两个问题的例子,第一个图像在工作时使用属性(createdAt)进行过滤,第二个传递整个文档返回空并且不能让 forEach 循环遍历数据
有人知道这是怎么回事吗?文档中没有任何复杂的信息,名称、创建日期、所有用于测试的数字。
如果有人遇到这个问题,请帮我解答,前几天刚开始学习 Firebase。 在此先感谢:)
// getting the data
const response = await db
.collection("apis")
.orderBy("createdAt")
.limit(3)
.get();
const dataSend = [];
response.forEach((document) => {
dataSend.push(document.data());
});
//triggering the next data load
const getMore = async () => {
const limit = 3;
const last = apis[apis.length - 1]; // last document
console.log(last); // {name: "3", description: "3", createdAt: t, url: "3", authorId: 123123, …}
try {
const response = await db
.collection("apis")
.limit(limit)
.orderBy("createdAt")
.startAfter(last.createdAt) // passing createdAt to fix the problem
.get();
console.log(response);
const dataSend = [];
response.forEach((document) => {
//this is not entering here
dataSend.push(document.data());
});
} catch .....
第二种情况
// getting the data
const response = await db
.collection("apis")
.orderBy("createdAt")
.limit(3)
.get();
const dataSend = [];
response.forEach((document) => {
dataSend.push(document.data());
});
//triggering the next data load
const getMore = async () => {
const limit = 3;
const last = apis[apis.length - 1]; // last document
console.log(last); // {name: "3", description: "3", createdAt: t, url: "3", authorId: 123123, …}
try {
const response = await db
.collection("apis")
.limit(limit)
.orderBy("createdAt")
.startAfter(last) // PASSING THE WHOLE DOCUMENT AS A PARAMETER DO NOT WORK
.get();
console.log(response);
const dataSend = [];
response.forEach((document) => {
//this is not entering here
dataSend.push(document.data());
});
} catch .....
【问题讨论】:
-
在 Stack Overflow 上,不要显示代码图片。将代码复制到问题中并设置格式,以便于阅读、复制和搜索。
-
@DougStevenson 抱歉,已修复。希望它现在更具可读性
标签: javascript firebase google-cloud-firestore