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
Release: 2024-12-11 02:18:13
Original
764 people have browsed it

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
Copy after login
let documentRef1 = firestore.doc('col/doc1');
let documentRef2 = firestore.doc('col/doc2');
firestore.getAll(documentRef1, documentRef2).then(docs => {...}); // Variant B
Copy after login

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"]);
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template