'Bulk way to determine of all paths, which one exists (Possibly in one API Call)
I have an array of strings and want to check which of all those documents exist in my Firestore in two ways:
I am using Node Admin SDK:
import Server from '../../../../firebase/firebase_server_exports';
export const databaseEntryExists = async (paths: string[]): Promise<string> => {
const promises = paths.map(
(element) =>
new Promise((resolve) => {
Server.db
.doc(element)
.get()
.then((doc) => resolve(doc.exists ? element : ''));
})
);
const results = await Promise.all(promises);
return results.includes(true) ? paths[results.indexOf(true)] : '';
};
Though this method works nicely, if I have 100 paths, I will be making 100 API calls which doesn't sound a good deal to me. Can someone suggest any Fierstore utility function or something like batch document fetching in order to reduce this to one API call?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
