I use the Firebase Emulator Suite to run and debug my Cload Functions locally, as described in this guide: https://firebase.google.com/docs/functions/local-emulator
I got a Cload Firestore Database ready-to-go with some data in it.
I try to fetch data from Cload Firestore through my locally emulated cload functions.
My approach so far was following the "Writing the Cloud Function Code" section in https://cloud.google.com/community/tutorials/cloud-functions-firestore
My functions/src/index.ts file looks like this:
import * as functions from 'firebase-functions';
const Firestore = require('@google-cloud/firestore');
const cors = require('cors')({origin: true});
const admin = require('firebase-admin');
admin.initializeApp();
const PROJECTID = 'XYZ';
const firestore = new Firestore({
projectId: PROJECTID
});
const logger = function(object: any){
console.log(JSON.stringify(object));
}
export const create_order = functions.https.onRequest((request, response) => {
cors(request, response, () => {
// var test_doc_id = "82GKB2P6xee9lftOidDj";
const trucks = firestore.collection("trucks").get();
logger(trucks);
response.send(JSON.stringify(firestore));
});
});
I expected the value of "trucks" to be an array of all trucks coming from firestore, but there is no result "{}" coming back.
Can someone give me hints, guides and suggestions how to do this in a correct way ?
Best regards, and thanks for your help