I am wondering if it's possible to get multiple documents by list of ids in one round trip (network call) to the Firestore.
相关问题
- adding sha1 in firebase app fails with error
- firebase storage cors strange Behaviour
- Firebase security rules difference between get() a
- Firebase security rules difference between get() a
- LoginActivty with Firebase & Facebook authenticati
相关文章
- How can make folder with Firebase Cloud Functions
- Firestore Update a document field Using Rest API
- How to convert a FCM token to APNS token?
- App not showing Notification receiving FCM when th
- Android Studio - Get Firebase token from GetIdToke
- How to combine Firestore orderBy desc with startAf
- Remove Duplicates from an Array of GeoFire Objects
- Is it possible to test a Firebase trigger locally?
You could use a function like this:
It can be called with a single ID:
or an array of IDs:
No, right now there is no way to batch multiple read requests using the Cloud Firestore SDK and therefore no way to guarantee that you can read all of the data at once.
However as Frank van Puffelen has said in the comments above this does not mean that fetching 3 documents will be 3x as slow as fetching one document. It is best to perform your own measurements before reaching a conclusion here.
Surely the best way to do this is by implementing the actual query of Firestore in a Cloud Function? There would then only be a single round trip call from the client to Firebase, which seems to be what you're asking for.
You really want to be keeping all of your data access logic like this server side anyway.
Internally there will likely be the same number of calls to Firebase itself, but they would all be across Google's super-fast interconnects, rather than the external network, and combined with the pipelining which Frank van Puffelen has explained, you should get excellent performance from this approach.
The best you can do is not use
Promise.all
as your client then must wait for.all
the reads before proceeding.Iterate the reads and let them resolve independently. On the client side, this probably boils down to the UI having several progress loader images resolve to values independently. However, this is better than freezing the whole client until
.all
the reads resolve.Therefore, dump all the synchronous results to the view immediately, then let the asynchronous results come in as they resolve, individually. This may seem like petty distinction, but if your client has poor Internet connectivity (like I currently have at this coffee shop), freezing the whole client experience for several seconds will likely result in a 'this app sucks' experience.
if you're within Node:
https://github.com/googleapis/nodejs-firestore/blob/master/src/index.js#L533
This doesn't seem to be possible in Firestore at the moment. I don't understand why Alexander's answer is accepted, the solution he proposes just returns all the documents in the "users" collection.
Depending on what you need to do, you should look into duplicating the relevant data you need to display and only request a full document when needed.