Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Prevent Firebase Firestore Emulator From Clearing The Database At Exit?

I'm Planning To Use Firebase - Firestore Emulators For Handling Some Huge Amount Of Data That's Coming From A Websocket.

I just need to process the data locally in realtime.

Firestore Emulator Is A great choice since it has all the features I need. But the issue is it clears the database every time the Emulator is turned off. is there any config or settings that can change this behaviour?

if it is not possible. can somebody tell me any other Approach to use firestore locally? or any other alternative to firebase that I can use locally.

like image 412
akashmohan Avatar asked Oct 27 '19 09:10

akashmohan


People also ask

How do I exit Firebase emulator?

Double tap CTRL-C (hold down CTRL and double tap C) in the terminal running the emulator when you want to shut down the emulator and clear all the ports and processes.

Does Firebase firestore cache?

Firestore supports offline data persistence. This feature caches a copy of the Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.

What is Firebase local emulator suite?

The Firebase Local Emulator Suite is a set of advanced tools for developers looking to build and test apps locally using Cloud Firestore, Realtime Database, Cloud Storage, Authentication, Cloud Functions, Pub/Sub, and Firebase Hosting. It provides a rich user interface to help you get running and prototyping quickly.

Does Firebase SDK export data when you stop the emulator?

Firebase SDK version: 8.0.0 When I stop my local firestore emulator most of the time it exports the data fine. However sometimes is has an error and it deletes my export files so I lose all my data. Nothing seems to appear in the logs. to stop the emulator. i emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.

Does the Cloud Firestore emulator clear database content when shutting down?

Note: The Cloud Firestore 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.

How to test FireStore from Python Firebase_admin SDK?

start the local Firebase emulators, run a test script, then shut down the emulators Since I put my test running command in a Makefile, I use the following command to test firestore from a Python firebase_admin SDK: The set-up and tear-down of the port is handled by firebase directly. So here's a bit of fun I just discovered.


2 Answers

With the recent updates to Firebase Emulator, you use export the data when the emulator is running and import when it starts again.

To export the data

firebase emulators:export <export-directory>

To start and import the emulator

firebase emulators:start --import <export-directory>
like image 164
Varun Rayen Avatar answered Sep 23 '22 12:09

Varun Rayen


I've managed this starting Firebase emulator with parameters to export data on exit and import existing one:

firebase emulators:start --import=exported-dev-data --export-on-exit=exported-dev-data

This way the emulator always export the data I've generated to folder exported-dev-data, and loads it back when starting again.

like image 25
Bivis Avatar answered Sep 25 '22 12:09

Bivis