I have a firebase project which has a project id and data in firestore. The app works great on the web, android studio, actual device etc to connect to my project firestore documents.
I want to create a cloud function so installed the firebase CLI, created a function but when i want to read data it will only access collections created at http://localhost:4000/firestore.
I have tried creating a serviceAcount from my firebase console.
const admin = require('firebase-admin');
var serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
I have tried using my known working firebaseConfig:
const admin = require('firebase-admin');
firebaseConfig = {
apiKey: "***************",
authDomain: "**********.firebaseapp.com",
projectId: "**********-****",
storageBucket: "*******-******.appspot.com",
messagingSenderId: "********",
appId: "1:***********:web:*************"
};
admin.initializeApp(firebaseConfig);
I have read everything (probably not) out there over the last couple days. It took me forever to even understand why the db.collection request was not returning anything, before i realized it was looking in another firestore bucket at http://localhost:4000/firestore (i created a document, and the cloud function immediately returned a working result). I thought I had figured it out.
How do i point the emulator to my existing firestore project data. I am clearly missing something really basic in understanding.