Export json from Firestore

后端 未结 9 2036
时光取名叫无心
时光取名叫无心 2020-12-14 05:55

As we can download json file at Firebase RTDB console, are there any way to export json file of Firestore collection/document data?

One of my main objectives is to c

相关标签:
9条回答
  • 2020-12-14 06:40

    It works for me.

    I used Cloud Functions to export all data in Firestore to JSON format. The function that I was used:

    exports.exportFirestore2Json = functions.https.onRequest((request, response) => {
        db.collection("data").get().then(function(querySnapshot) {
            const orders = [];
            var order = null
    
             querySnapshot.forEach(doc => {
                 order = doc.data();
                 orders.push(order);
             });
    
             response.send(JSON.stringify(orders))
    
             return true
        })
        .catch(function(error) {
            console.error("Error adding document: ", error);
            return false
        });
    })
    

    Then, go to https://your-project-id.cloudfunctions.net/exportFirestore2Json you will see something like this

    0 讨论(0)
  • 2020-12-14 06:48

    I just wrote a backup and restore for Firestore. You can have a try on my GitHub.

    https://github.com/dalenguyen/firestore-backup-restore

    Thanks,

    0 讨论(0)
  • 2020-12-14 06:48

    Google made it harder than it needed to be, so the community found a workaround. If you have npm installed, you can do this:

    Export

    npx -p node-firestore-import-export firestore-export -a credentials.json -b backup.json
    

    Import

    npx -p node-firestore-import-export firestore-import -a credentials.json -b backup.json
    

    Source

    0 讨论(0)
提交回复
热议问题