TheGoogle Cloud CLIprovides a local, in-memory emulator for
Firestore that you can use to test your application. You can use the
emulator with all Firestore client libraries. You should use
the emulator only for local testing.
Do not use the emulator for production deployments. Because the emulator stores
data only in memory, it will not persist data across runs.
Install the emulator
To install the Firestore emulator, install and update the
gcloud CLI:
Update your gcloud CLI installation to get the latest
features:
gcloud components update
Run the emulator
Run the following command to start the emulator:
gcloud emulators firestore start
The emulator prints the host and port number where it is running.
By default, the emulator attempts to use127.0.0.1:8080. To bind the
emulator to a specific host and port, use the optional--host-portflag,
replacingHOSTandPORT:
TypeControl + Cto stop the emulator. The emulator may also be stopped
with a POST to/shutdown. For example:
curl -d ''HOST:PORT/shutdown
Connect to the emulator
How you connect to the emulator depends on the type of client library, server
client library, or mobile/web SDK.
Server client libraries
To connect a Firestore server client
library (C#, Go, Java, Node.js, PHP, Python, and Ruby),
set theFIRESTORE_EMULATOR_HOSTenvironment variable. When this environment
variable is set, the server client libraries automatically connect to the emulator.
exportFIRESTORE_EMULATOR_HOST="HOST:PORT"
Android, Apple platforms, and Web SDKs
The following examples demonstrate how to connect the
Android, Apple platforms, and Web SDKs to the Firestore
emulator:
Android
// 10.0.2.2 is the special IP address to connect to the 'localhost' of// the host computer from an Android emulator.FirebaseFirestorefirestore=FirebaseFirestore.getInstance();firestore.useEmulator("10.0.2.2",8080);FirebaseFirestoreSettingssettings=newFirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build();firestore.setFirestoreSettings(settings);
The Firestore in Native Mode emulator clears database contents when shut down. Since
the offline cache of the Firestore SDK is not automatically cleared, you may
want to disable local persistence in your emulator configuration to avoid
discrepancies between the emulated database and local caches; in the Web SDK,
persistence is disabled by default.
Clear emulator data
The Firestore emulator includes a REST endpoint for deleting all
the data currently in the emulator. You can use this endpoint to clear data
between tests without shutting down the emulator.
To delete all data in the emulator, perform an HTTPDELETEoperation against
the following endpoint, replacingHOSTandPORTwith the
host and port you selected and replacingPROJECT_IDwith your
own project ID:
How the Firestore emulator differs from production
The Firestore emulator attempts to faithfully replicate the
behavior of the production service with some notable limitations.
Transactions
The emulator doesn't attempt to mimic the transaction behavior that's seen in
production. It uses a simple locking approach and doesn't attempt to mirror
the various concurrency modes offered in the production environment.
When you're testing features that involve multiple concurrent writes to one
document, the emulator might be slow to complete write requests. It might take
up to 30 seconds for the emulator to release the locks. If you need to adjust
the test timeout intervals, then do so.
The emulator doesn't also attempt to mimic all of theproduction limits, such as
timeouts & size limits, which involve transactions. If you test features that
depend on these production limits, then we recommend that you use a production
environment instead of an emulator.
Indexes
The emulator does not track composite indexes and will instead execute any
valid query. Make sure to test your app against a real Firestore
instance to determine which indexes you require.
Limits
The emulator does not enforce all limits enforced in production. For example,
the emulator may allow transactions that would be rejected as too large by the
production service. Make sure you are familiar with thedocumented limitsand that you design your app to
proactively avoid them.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-10-31 UTC."],[],[]]