I'm writing some data to firestore using the nodejs firebase-admin/firestore package, on an endpoint running on firebase functions.
When running this endpoint locally using the firebase emulator, the data gets written both to the local emulator, and to the actual project data hosted by google.
Why is this happening? I only want it locally.
The command I'm using to run the endpoint:
firebase emulators:start --only functions,firestore
Code to initialise the firebase admin (and I've verified that getEnv does equal the local environment when running locally):
import { initializeApp } from "firebase-admin/app"
import { getFirestore } from "firebase-admin/firestore"
import { Environment, getEnv } from "../Config"
if (getEnv() === Environment.LOCAL) {
process.env["FIRESTORE_EMULATOR_HOST"] = "localhost:8080"
}
initializeApp()
const db = getFirestore()
db.settings({ ignoreUndefinedProperties: true })
export { db }
My firebase.json:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"hosting": {
"public": "client/build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true
}
}
}
My code to create the document
await db.collection("Lead").doc(leadId).create({
companyName,
fullName,
...
})