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

Bad parsing of arrays of DocumentReferences

francescopellegrini opened this issue · comments

Given an exported data as follows:

const data = {
  collection1: {
    docId: {
      refArray: [
        {path:'collection1/document1-ref'},
        {path:'collection2/document2-ref'}
      ]
    }
  }
}

the refArray field gets parsed into 'collection2/document2-ref instead of an array of strings.

This is because the field is completely overridden while looping on the original array.

for (let val of data[collectionName][doc.id][refKey]) {
data[collectionName][doc.id][refKey] = getPath(val)
}

The appropriate way of mapping the array values can be seen in import.ts:

data[ref] = data[ref].map((ref) => db.doc(ref))