I'm trying to do a simple firestore query, using a where clause inside firebase cloud functions but I get foo.data is not a function.
exports.uploadList = functions.https.onRequest(async (req, res) => {
try {
let foo = await db.collection('users').where('appToken', '==', 'xxxx').get()
if (foo) {
return res.status(200).send({ foo: foo.data() })
}
} catch (error) {
return res.status(500).send(error)
}
})
The response I get is an empty object {}, if I remove the try/catch block I can see an error in cloud functions log foo.data is not a function.
I read that where() is optional so also tried db.collection('users').get(), same result.
I can query using db.collection().doc().get() and it works fine but no way to find a document by a field value. set and update also work fine.