无法从 Firestore React-Native 获取所有数据
我无法在我的 React Native 应用程序中从 Firestore 获取所有数据。当我添加 limit(200) 参数时,我可以获取数据,但是当我删除 limit 参数时,我的应用程序崩溃了。我需要显示所有数据,但我不知道我做错了什么,这是我的代码:
const listingsRef = firebase.firestore().collection(ServerConfiguration.database.collection.LISTINGS);
if (categoryId === '') {
console.log('Kommer vi hit???');
return listingsRef
.where('isApproved', '==', isApproved)
.limit(2000)
.onSnapshot((querySnapshot) => {
const data = [];
if (querySnapshot !== undefined) {
querySnapshot.forEach((doc) => {
const listing = doc.data();
if (favorites && favorites[doc.id] === true) {
listing.saved = true;
}
data.push({ ...listing, id: doc.id });
});
console.log('KOMMERR datan? : ', data);
callback(data);
}
});
}
我尝试使用 get 而不是 Snapshot,并且得到相同的结果。我已经被困了好几天了!
I can't fetch all data from Firestore in my react native app. I can fetch data when I add a limit(200) parameter but when I take away the limit parameter my app crashes. I need to display all the data and I don't know what I'm doing wrong, here is my code:
const listingsRef = firebase.firestore().collection(ServerConfiguration.database.collection.LISTINGS);
if (categoryId === '') {
console.log('Kommer vi hit???');
return listingsRef
.where('isApproved', '==', isApproved)
.limit(2000)
.onSnapshot((querySnapshot) => {
const data = [];
if (querySnapshot !== undefined) {
querySnapshot.forEach((doc) => {
const listing = doc.data();
if (favorites && favorites[doc.id] === true) {
listing.saved = true;
}
data.push({ ...listing, id: doc.id });
});
console.log('KOMMERR datan? : ', data);
callback(data);
}
});
}
I have tried to use get instead of on Snapshot, and I get the same results. I have been stuck for days!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将限制替换为获取并获取所有满足您条件的记录。
但当您有大量数据时,对结果进行分页始终是一个好主意
You can replace the limit with getting and getting all the records that satisfy your condition.
But its always a good idea to paginate your results when you have large amount of data