This application uses the Google Cloud Firestore client libraries and is compatible with Native Image compilation.
This sample runs through basic operations of creating a new document, running queries, and then deleting the created resources.
-
Follow the GCP Project and Native Image Setup Instructions.
-
If you wish to run the application against the Firestore emulator, make sure that you have the Google Cloud SDK installed.
In a new terminal window, start the emulator via
gcloud
:gcloud beta emulators firestore start --host-port=localhost:9010
Leave the emulator running in this terminal for now. In the next section, we will run the sample application against the Firestore emulator instsance.
-
Navigate to this directory and compile the application with the Native Image compiler.
mvn package -P native
-
(Optional) If you're using the emulator, export the
FIRESTORE_EMULATOR_HOST
as an environment variable in your terminal.export FIRESTORE_EMULATOR_HOST=localhost:9010
The Firestore Client Libraries will detect this environment variable and automatically connect to the emulator instance if this variable is set.
-
Run the application.
./target/firestore-sample
-
The application will run through some basic Firestore operations and log some output statements.
Created user alovelace. Timestamp: 2020-12-15T20:19:28.444070000Z The following users were saved: Document: alovelace | Ada Lovelace born 1815 Number of users born before 1900: 1 Number of users born earlier after 1900: 0 Number of users whose first name is 'Ada': 0