Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to export refs in arrays #124

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const backupFromDoc = async <T>(
if (data[collectionName][doc.id][refKey]) {
if (Array.isArray(data[collectionName][doc.id][refKey])) {
for (let val of data[collectionName][doc.id][refKey]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, do you think that we should also remove the forloop for (let val of data[collectionName][doc.id][refKey])?

Did it work when you test it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've "tried" basically by updating transpiled code in dist folder of your library (i know, its bad, thus the PR ^^).

Before doing this it would not let me export arrays containing references, but then once I've added this line and re-run my yarn firestore:sync export script (see attached) it started to behave as it should.

Anyway, I think we have two choices here (or maybe more):

if (Array.isArray(data[collectionName][doc.id][refKey])) {
  for (let val of data[collectionName][doc.id][refKey]) {
    data[collectionName][doc.id][refKey] = db.doc(getPath(val));
  }
}
if (Array.isArray(data[collectionName][doc.id][refKey])) {
  data[collectionName][doc.id][refKey] = data[collectionName][doc.id][refKey]
    .map((ref) => db.doc(getPath(ref)));
}

What do you think is better? Also could you please validate that it works for you, as I'm pretty newbie with Firebase, i wouldn't want to mess with people's projects ^^

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WNemencha can you send a snapshot of your sample data in firestore & the result after you backup?

data[collectionName][doc.id][refKey] = getPath(val)
data[collectionName][doc.id][refKey] = data[collectionName][doc.id][refKey].map((ref) => db.doc(ref));
}
} else if (
typeof data[collectionName][doc.id][refKey].path === 'string'
Expand Down