Skip to content

whereHavingExample sample throws error #2366

@bhshkh

Description

@bhshkh

void whereHavingExample() throws ExecutionException, InterruptedException {
// [START where_having_example]
Pipeline.Snapshot cities =
firestore
.pipeline()
.collection("cities")
.aggregate(
Aggregate.withAccumulators(sum("population").as("totalPopulation"))
.withGroups("location.state"))
.where(field("totalPopulation").greaterThan(10000000))
.execute()
.get();
// [END where_having_example]
System.out.println(cities.getResults());
}

throws error

Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: The nested field reference 'location.state' is not supported in its current use case.

Certain stages like `aggregate(...)` or `unnest(...)` only support assigning to top-level fields. This means you cannot use an alias like 'foo.bar' to assign the result to a nested field. If you want to use an alias that has a dot in it, escape the path with backticks, like `foo.bar`.

Depending on the SDK, this can be done like so:`.distinct(field("address.city").as("`address.city`"))`
	at io.grpc.Status.asRuntimeException(Status.java:532)

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/java-firestore API.samplesIssues that are directly related to samples.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions