Back

Download all documents from appwrite collection in React

  • 0
  • Databases
  • Web
thejunghare
13 Jun, 2024, 08:32

In my app-write database I have a collection with documents and I have to download all the documents with a click in my react app I have write the script but the issue is it only download first 26 document. I have around 1000 document and I have to download then all at once

import React from 'react'; import { Databases, Client } from 'appwrite';

const appwrite = new Client(); appwrite .setEndpoint('https://cloud.appwrite.io/v1') // Set your Appwrite endpoint .setProject('your-project-id'); // Set your project ID

const database = new Databases(appwrite);

async function dumpCollection(collectionId) { try { // Adjust the listDocuments call to include databaseId and any necessary parameters const response = await database.listDocuments('your-database-id', collectionId); const documents = response.documents; // Extract documents from the response const json = JSON.stringify(documents); const blob = new Blob([json], { type: 'application/json' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'collection.json'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } catch (error) { console.error(Failed to dump collection: ${error.message}); } }

const App = () => { return ( <button onClick={() => dumpCollection('your-collection-id')}> Download Collection </button> ); }

export default App;

I have write the script but the issue is it only download first 26 document. I have around 1000 document and I have to download then all at once

TL;DR
Developers wants to download all documents from an Appwrite collection in a React app using a script, but it's only downloading the first 26 documents out of 1000. To fix this, adjust the script to handle pagination or include a loop to fetch all documents at once.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more