googleapis / googleapis/google-cloud-java

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

Aperta
#13,135 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
api: firestore priority: p2 type: bug
Lingua principale
Java
Stelle
2.1k
Fork
1.2k
Merge medio
1g 23h
PR unite (30g)
154

Descrizione

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
}
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.