From 6228dc8f67d88dd5fd3fc470b44a12c5a05a340a Mon Sep 17 00:00:00 2001 From: Chidindu Ogbonna Date: Fri, 26 Jun 2020 15:49:45 +0100 Subject: [PATCH 1/2] update: If snapshot is empty, resolve empty Without this, the whole process ended if a document did not have that collection --- export.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/export.js b/export.js index 72e6381..f4d459e 100644 --- a/export.js +++ b/export.js @@ -54,6 +54,11 @@ function addSubCollection(key, subData){ return new Promise(resolve => { db.collection(collectionName).doc(key).collection(subCollection).get() .then(snapshot => { + + if (snapshot.empty) { + resolve('Empty') + } + snapshot.forEach(subDoc => { subData[subDoc.id] = subDoc.data(); resolve('Added data'); From da8d7b57eeefbf5f6a14e2559c50f38441d64839 Mon Sep 17 00:00:00 2001 From: Chidindu Ogbonna Date: Fri, 26 Jun 2020 15:58:24 +0100 Subject: [PATCH 2/2] update: Let the actual name of the subcollection be used in the json file Using the actual name gives more information in the exported json file --- export.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/export.js b/export.js index f4d459e..86a6003 100644 --- a/export.js +++ b/export.js @@ -44,10 +44,10 @@ results.then(dt => { async function getSubCollection(dt){ for (let [key, value] of Object.entries([dt[collectionName]][0])){ if(subCollection !== undefined){ - data[collectionName][key]['subCollection'] = {}; - await addSubCollection(key, data[collectionName][key]['subCollection']); - } - } + data[collectionName][key][`${subCollection}`] = {}; + await addSubCollection(key, data[collectionName][key][`${subCollection}`]); + } + } } function addSubCollection(key, subData){