Difference between starting firestore emulator through `firebase` and `gcloud`?

2024/11/14 23:24:22

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?

Answer

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.

https://en.xdnf.cn/q/71503.html

Related Q&A

PyInstaller icon option doesnt work on Mac

I ran the following command on my mac and created an .app file.pyinstaller --icon icon.icns --noconsole -n testApp main.pyHowever, the generated .app file does not show the icon.icon.icns is specified …

Error Installing scikit-learn

When trying to install scikit-learn, I get the following error:Exception:Traceback (most recent call last):File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2…

Issues downloading Graphlab dependencies get_dependencies()

I am having trouble when I try to download the dependencies needed to run graphlab. I do import graphlab I get the following:ACTION REQUIRED: Dependencies libstdc++-6.dll and libgcc_s_seh-1.dll not fou…

Django Tastypie slow POST response

Im trying to implement a Tastypie Resource that allows GET & POST operations following a per user-permission policy, the model is pretty simple (similar to the Note model in Tastypie documentation)…

Extract a region of a PDF page by coordinates

I am looking for a tool to extract a given rectangular region (by coordinates) of a 1-page PDF file and produce a 1-page PDF file with the specified region:# in.pdf is a 1-page pdf file extract file.pd…

Is it possible to concatenate QuerySets?

After a search of a database I end up with an array of querysets. I wanted to concatenate these queryset somewhat like we can do with list elements. Is this possible or maybe there an altogether better…

Pickling a Python Extension type defined as a C struct having PyObject* members

I am running C++ code via Python and would like to pickle an extension type.So I have a C++ struct (py_db_manager) containing pointers to a database object and a object manager object (both written in …

Generating random ID from list - jinja

I am trying to generate a random ID from a list of contacts (in Python, with jinja2) to display in an HTML template. So I have a list of contacts, and for the moment I display all of them in a few cell…

Unit testing Flask app running under uwsgi

I’m relatively new to python and am looking for a pythonic way to handle this practice. I’ve inherited a fairly trivial Python 2.7 Flask app that runs under uwsgi that I want to add some unit tests t…

fastest way to find the smallest positive real root of quartic polynomial 4 degree in python

[What I want] is to find the only one smallest positive real root of quartic function ax^4 + bx^3 + cx^2 + dx + e [Existing Method] My equation is for collision prediction, the maximum degree is quarti…