-
Notifications
You must be signed in to change notification settings - Fork 517
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
base: main
Are you sure you want to change the base?
Conversation
|
examples/CloudFirestore.md
Outdated
.collection(`users`) | ||
.where(admin.firestore.FieldPath.documentId(), `in`, keys) | ||
.get(); | ||
return snapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id })); |
There was a problem hiding this comment.
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:
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.)
There was a problem hiding this comment.
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.
@saihaj Alas I use neither DataLoader nor Firestore so cannot really review the PR. |
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.