#Hello I used appwrite to display data on my app but only 25 documents are showing from my collection
20 messages · Page 1 of 1 (latest)
As in you are using listdocuments function and it only returns 25 docs from collection?
Use Query.limit(50) or any other number to get the required number of documents.
No like
I have a collection and inside that collection I have more than 25 documents but only 25 are showing on my app
Can you give your code snippet?
I ment the part of code that is used to fetch from appwrite
const fetchNotificationData = async () => { setLoading(true);
setRefreshing(true); let progress = 1;
const progressInterval = setInterval(() => { if (progress <= 100) {
setLoadingProgress(progress); progress++;
} }, 50);
try {
const response = await database.listDocuments(databaseId, collectionId); const notifications = response.documents;
setNotificationData(notifications); setFilteredNotifications(notifications);
setNewNotificationsCount(notifications.length);
// Save to AsyncStorage for persistence await AsyncStorage.setItem('notifications', JSON.stringify(notifications));
await AsyncStorage.setItem('newNotificationsCount', notifications.length.toString()); } catch (error) {
console.error('Error fetching notification data:', error); } finally {
clearInterval(progressInterval); setLoading(false);
setRefreshing(false); }
};
So the thing is
list document function returns 25 documents by default.
If you want to increase it you can use Query.limit(any amount you want)
If it is a chat like system
I reccomend pagination
The limit is upto 5000
But there might be a loading and memory issue for that, just load by batch
Like As we scroll up to see the older messages we might have to wait a sec for prev message to load.
This reduces the load
This is the view
Got it , but still
Pagination is better way to load it.
From your app, i can see it will cross 200+ easily
// Fetch the first 5000 notifications using query.limit and query.offset
let allNotifications = [];
let offset = 0;
const limit = 1000; // Maximum limit for each request (Appwrite allows up to 1000 per request)
while (allNotifications.length < 5000) {
const response = await database.listDocuments(databaseId, collectionId, [
Query.limit(limit),
Query.offset(offset),
]);
const notifications = response.documents;
allNotifications = [...allNotifications, ...notifications];
if (notifications.length < limit) break; // If there are fewer documents than the limit, stop the loop
offset += limit; // Increment the offset by the limit to fetch the next set of documents
}
I am getting this error
Is it solved? Or still facing the same?