What is the difference between starting the firestore emulator through:
firebase emulators:start --only firestore
and:
gcloud beta emulators firestore start
Both options allow my python app to achieve connectivity with the database like so:
import google
from google.cloud import firestoreos.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8081"
os.environ["FIRESTORE_EMULATOR_HOST_PATH"] = "localhost:8081/firestore"
os.environ["FIRESTORE_HOST"] = "http://localhost:8081"credentials = mock.Mock(spec=google.auth.credentials.Credentials)
client = firestore.Client(credentials=credentials)
One difference I've noticed myself is that firebase
seems to respect my firebase.json
, specifically the host port specified like so:
{"emulators": {"firestore": {"port": "8081"}}
}
On the other hand, gcloud
ignores firebase.json
and instead chooses a random port unless I explicitly pass a port through --host-port
. Is this part of a bigger difference between the two, and what are some other differences?
I have been looking on the documentation for both tools and they do almost the same thing.
Using the Firebase tool you can start emulators for multiple Firebase products whereas the gcloud command allows you to start GCP emulators. Firestore is simply a product they both have in common and as such their utility should be the same or similar.
About the functionality differences, firebase
provides the --import
and --export-on-exit
flags that allow you to save and recover data between emulated sessions. It also provides a way to visualize how the security rules are dealing with the current queries.
Apart from those functionalities I would note the different ways to setup the port and the rules file:
firebase emulators
uses the firebase.json
file.
gcloud beta emulators
uses the flags --host-port
and --rules
to achieve the same functionality.
Notice that the Firestore emulator on GCP is on the beta stage thus it may have limited official support and may be subject to change. Also notice how, on GCP's Firestore documentation, the Firebase CLI is used instead of gcloud.
In the end you should use your preferred tool, as they both work towards the same goal of emulating Firestore. If you are already working with the Firebase CLI, I would recommend you to keep using it; if you are working with gcloud
, use that.