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

Make it possible to export refs in arrays #124

wants to merge 1 commit into from

Conversation

WNemencha
Copy link

Closes #110 (i hope)

@@ -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?

@WNemencha WNemencha closed this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad parsing of arrays of DocumentReferences
2 participants