I would just like to access my Firestore Database from within my Firebase Functions. I have tried to follow all the documentation and other stack overflow questions but still it is not working. Here is my code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.test = functions.https.onRequest((request, response) => {
admin
.firestore()
.collection('users')
.get()
.then(querySnapshot => {
const arrUsers = querySnapshot.map(element => element.data());
return response.send(arrUsers);
}).catch((error) => {
// It is coming in here, and this below just returns '{}'
response.send(error);
});
});
What am I doing wrong?