googleapis / googleapis/google-cloud-java

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

Ouverte
#13,135 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
api: firestore priority: p2 type: bug
Langage dominant
Java
Étoiles
2.1k
Forks
1.2k
Merge moyen
1 j 23 h
PR mergées (30 j)
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
}
}
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.