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

Add example for Cloud Firestore #268

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shoNagai
Copy link

@shoNagai shoNagai commented May 8, 2021

DataLoader is a great feature.
I'm using Cloud Firestore, and I've thrown in a pull request to add sample documentation, which I hope will increase the number of Cloud Firestore use cases.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 8, 2021

CLA Signed

The committers are authorized under a signed CLA.

benjie
benjie previously requested changes May 10, 2021
.collection(`users`)
.where(admin.firestore.FieldPath.documentId(), `in`, keys)
.get();
return snapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id }));
Copy link
Member

Choose a reason for hiding this comment

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

Does firestore guarantee the results will be in the same order as the keys input? If you're not sure this is the case, I think it might be safer if this line was something like:

Suggested change
return snapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id }));
return keys.map(key => {
const doc = snapshot.docs.find(doc => doc.id === key);
return doc ? { ...doc.data(), id: doc.id } : null;
});

(Obviously test this works before adopting it; I've never used Firestore.)

Copy link
Author

Choose a reason for hiding this comment

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

@benjie
Thank you for your review.

As you said, firestore is retrieved in ascending order by document ID by default, so I think sorting by input key is necessary.

I have added the correction and comments.

I have also implemented and confirmed the test in my repository.

@shoNagai shoNagai requested a review from benjie June 3, 2021 13:04
@benjie benjie removed their request for review June 3, 2021 13:15
@benjie benjie dismissed their stale review June 3, 2021 13:15

Changes made

@saihaj saihaj mentioned this pull request Mar 11, 2022
26 tasks
@saihaj saihaj requested a review from benjie March 25, 2022 03:05
@benjie
Copy link
Member

benjie commented Mar 25, 2022

@saihaj Alas I use neither DataLoader nor Firestore so cannot really review the PR.

@benjie benjie removed their request for review March 25, 2022 11:02
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.

2 participants