#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)

marsh quest
#

How can I solve that?

lucid arrow
dim light
#

Use Query.limit(50) or any other number to get the required number of documents.

marsh quest
lucid arrow
lucid arrow
# marsh quest

I ment the part of code that is used to fetch from appwrite

marsh quest
#

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); }
};

lucid arrow
#

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

marsh quest
#

It’s like a notification list

#

Can I use Query.limit to make it fetch all data’s

lucid arrow
lucid arrow
#

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

marsh quest
#

This is the view

lucid arrow
#

Got it , but still
Pagination is better way to load it.
From your app, i can see it will cross 200+ easily

marsh quest
#

// 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 
  }
marsh quest
#

I am getting this error

lucid arrow
#

Is it solved? Or still facing the same?