I'm building a web app with a React front end hosted on Firebase Hosting that uses scheduled Pub/Sub Firebase Functions to scrape data and store it in a Firestore database (which is also access in the front end). This is my first time using Firebase.
tl;dr, can I do this in a Firebase Function?
const q = query(citiesRef,
or(where('capital', '==', true),
where('population', '>=', 1000000)
)
);
I've been trying to use the new "Logical OR" query feature for a Firestore query from within a Firebase Function. The docs show code samples implying that this feature can be used via the "Web modular API" (which seems to only be accessible via the "Web SDK"...which would mean my React front end in my case?), but also implies, for some unclear reason, that it is not usable via the "Web namespaced API" or Node.js—both of which seem to be preferred flavors within Firebase Functions, which I believe use a toolset called the "Firebase Admin SDK" to access Firestore functionality.
Basically, I'd like to use this feature within a Firebase Function. Is this just not (yet?) possible?
Other Firebase documentation led me to believe it might be possible, but I think I may have been confusing similarly named syntaxes/functionalities/services... I'm not sure. Some docs refer to it being possible to "upgrade" to a "modular SDK" version of the "Admin SDK"...and that now there's a "2nd generation" mentioned in yet another doc which is more "modular"... but is maybe actually unrelated to the "Web modular API," which allows the functionality I was looking to use in a Firebase Function?
Any help untangling this would be greatly appreciated!
Ok, based on answers like this and further scouring the docs, I don't think it is possible to use Web modular API-like syntax within the Node.js Admin SDK (and hence within a Firebase Functions function).
However, it seems that the Firestore docs were literally just updated within the last 24 hours... with a snippet showing that logical OR queries CAN be done in the Admin SDK(!) with a new Filter
object, like this:
const bigCities = await citiesRef
.where(
Filter.or(
Filter.where('capital', '==', true),
Filter.where('population', '>=', 1000000)
)
)
.get();
While it's great to find out that this functionality is available in both the Web API and the Node.js/Admin SDK/Firebase Functions, I think the fact that both the Web API and the Admin SDK use JS and ESM, but that one (the Node.js Admin SDK) can't use the same syntax as the other is extremely confusing for the uninitiated and not well-documented.
Some clarification in the docs could be really helpful.