Export json from Firestore

后端 未结 9 2038
时光取名叫无心
时光取名叫无心 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

提交回复
热议问题