dalenguyen / firestore-backup-restore

NPM package for backup and restore Firebase Firestore

Home Page:https://firebaseopensource.com/projects/dalenguyen/firestore-backup-restore/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error handling question

Ihatetomatoes opened this issue · comments

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.

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.

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?

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

Thanks for the clarification @dalenguyen .