dalenguyen / firestore-backup-restore

NPM package for backup and restore Firebase Firestore
https://firebaseopensource.com/projects/dalenguyen/firestore-backup-restore/
MIT License
493 stars 83 forks source link

Error handling question #156

Closed Ihatetomatoes closed 7 months ago

Ihatetomatoes commented 7 months ago

Thanks for the handy utility. I have a few questions regarding restoring.

If I use the restore() to import collection with 100 objects, will that result in 100 writes into firebase?

What happens if one of these documents fail to import? Will all 100 imports fail or only the one? Will the error message contain the information about successful and failed imports?

I need to know so I know what UI to show user in case something fails.

dalenguyen commented 7 months ago

Hi @Ihatetomatoes, it will takes 100 writes to the database if you have 100 objects. If one of the these documents fails, the other still works. There're log messages that will show you status of the import.

Ihatetomatoes commented 7 months ago

Thanks @dalenguyen, is there a way to get the number of documents that have been created?

I have nextjs API route that takes an object and imports it to firebase and I want to show to the user how many documents were created.

Currently the response only contains generic message:

const response = await restore(db, JSON.parse(collection));

{
    "status": true,
    "message": "Collection successfully imported!"
}

Is there a way to get the count of documents created or failed from the response?

dalenguyen commented 7 months ago

There is an option where can pass showLogs options when importing. Normally, if there's no error log, all docs are imported correctly.

https://github.com/dalenguyen/firestore-backup-restore?tab=readme-ov-file#import--restore-options

Ihatetomatoes commented 7 months ago

Thanks for the clarification @dalenguyen .