googleapis / googleapis/google-cloud-java

[java-firestore] [Emulator] Does this library work with the firebase firestore emulator?

Open
#13,135 1 comment 0 reactions 0 assignees View on GitHub
api: firestore priority: p2 type: bug
Dominant language
Java
Stars
2.1k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
154

Description

I've been trying to get this library to work with the firestore emulator, and I actually thought for a while that it was working as requests succeed when I write and a project id hasn't been set. The requests aren't actually being saved to the database though. When I look at the emulator database viewer, there is no data.

#### Environment details

2. OS type and version: Mac Big Sur
3. Java version: Java 11
4. firestore version(s): Latest

#### Steps to reproduce

1. Setup Firestore in java code
2. Write data to firestore
3. Requests succeed
4. Try and read data
5. Data doesn't exist

If I set a project id, I get exceptions with clear failures.

#### Code example

```Kotlin
object FirestoreProvider {
const val ENV_FIRESTORE_EMULATOR_HOST = "FIRESTORE_EMULATOR_HOST"
const val ENV_FIRESTORE_DATABASE_ID = "FIRESTORE_DATABASE_ID"

fun create(): Firestore {
val firestoreHost = System.getenv().getOrDefault(ENV_FIRESTORE_EMULATOR_HOST, "localhost:9102")
val isEmulator = firestoreHost.contains("localhost")

println("Using $firestoreHost for the Firestore host.")
println("It is ${if (isEmulator) "" else "not "}being configured as an emulator")

var builder = FirestoreOptions.newBuilder()

if (isEmulator) {
builder = builder
.setEmulatorHost(firestoreHost)
.setCredentials(FirestoreOptions.EmulatorCredentials())
}

return builder.build().service
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.