Home >Web Front-end >JS Tutorial >Can I Fetch Multiple Firestore Documents with One Request?

Can I Fetch Multiple Firestore Documents with One Request?

DDD
DDDOriginal
2024-12-11 02:18:13795browse

Can I Fetch Multiple Firestore Documents with One Request?

Fetching Multiple Firestore Documents with a Single Request

Question:

Is it possible to retrieve multiple Firestore documents with a single network call using a list of IDs?

Answer:

Yes, there are ways to achieve this using Firestore's SDKs:

Node.js:

firestore.getAll(...documents); // Variant A
let documentRef1 = firestore.doc('col/doc1');
let documentRef2 = firestore.doc('col/doc2');
firestore.getAll(documentRef1, documentRef2).then(docs => {...}); // Variant B

Note: Variant A only works with the Server SDK.

Update:

Firestore now supports IN queries, which provides a more efficient way to retrieve multiple documents by a list of IDs:

myCollection.where(firestore.FieldPath.documentId(), 'in', ["123","456","789"]);

The above is the detailed content of Can I Fetch Multiple Firestore Documents with One Request?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn