Firebase emulator return empty data whereas working fine after deploying
See original GitHub issuefirebase-tools: 8.1.1
Platform: Ubuntu
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
I am not sure how I ran into this problem. I just followed the doc to run and debug the functions on emulator. After “firebase init”, I selected the firestore, functions and datastore emulators and all the dependencies were successfully installed. Later I started the emulator and it’s start the firestore, functions and datastore emulators on different port. Then I tried to execute my function and got no data in response.
export const activeServices = functions.https.onRequest((request, response) => {
let services = new Array<string>();
admin.firestore().collection(newServices).get()
.then(serviceSnapshot => {
serviceSnapshot.docs.forEach(doc => {
if(doc.data().service_active){
services.push(doc.data().service_name)
}
})
const successResponse = common.success("success", 200, "Services retrieved", services)
response.send(successResponse)
})
.catch(error => {
const errorResponse = common.error("fail", 500, "Failed to get active services")
console.error(errorResponse)
response.send(errorResponse)
})
})
I tried to execute this and it return nothing and executed the same functions after deploying. And I got the response.
I think running only functions will try to communicate with production database.
firebase emulators:start --only functions
functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
⚠ External network resource requested!
- URL: "http://xxx.xxx.xxx.xxx/computeMetadata/v1/instance"
- Be careful, this may be a production service.
⚠ External network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
- Be careful, this may be a production service.
This looks like it’s trying to communicate to production but couldn’t make any successful request.
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (9 by maintainers)
Even am facing the same issue
My firestore emulator run on localhost:5000
db.collection("myfirstcollection").doc("dataexitsinthedocument").get() .then(snapShot=>{ if(snapShot.exists){ console.log(snapShot.data()) }else{ console.log("no data to fetch") } }) .catch(error=>{console.log(error);console.log(error)}) .finally(()=>{ console.log("exit on final") })
I have connected to my firestore using `if (window.location.hostname === “localhost”) {
}`
@Tzahile I don’t quite understand the situation you’re describing but here’s how it works:
firebase-admin
will use data from the RTDB emulatorfirebase-admin
will use data from production