Toplu
Tüm toplama işlevleri, aggregate(...) aşamasında üst düzey ifadeler olarak kullanılabilir.
| Ad | Açıklama |
COUNT
|
Belge sayısını döndürür. |
COUNT_IF
|
Bir ifadenin TRUE olarak değerlendirildiği dokümanların sayısını döndürür.
|
COUNT_DISTINCT
|
Benzersiz ve boş olmayan NULL değerlerin sayısını döndürür.
|
SUM
|
Tüm NUMERIC değerlerinin toplamını döndürür.
|
AVERAGE
|
Tüm NUMERIC değerlerinin ortalamasını döndürür.
|
MINIMUM
|
NULL olmayan minimum değeri döndürür.
|
MAXIMUM
|
Maksimum NULL olmayan değeri döndürür.
|
FIRST
|
İlk dokümanın expression değerini döndürür.
|
LAST
|
Son belgenin expression değerini döndürür.
|
ARRAY_AGG
|
Tüm giriş değerlerinin dizisini döndürür. |
ARRAY_AGG_DISTINCT
|
Tüm farklı giriş değerlerinin dizisini döndürür. |
COUNT
Söz dizimi:
count() -> INT64
count(expression: ANY) -> INT64
Açıklama:
expression değerinin NULL dışındaki herhangi bir değer olarak değerlendirildiği önceki aşamadaki dokümanların sayısını döndürür. expression sağlanmazsa önceki aşamadaki toplam belge sayısını döndürür.
Node.js
// Total number of books in the collection const countOfAll = await db.pipeline() .collection("books") .aggregate(countAll().as("count")) .execute(); // Number of books with nonnull `ratings` field const countField = await db.pipeline() .collection("books") .aggregate(field("ratings").count().as("count")) .execute();
Web
// Total number of books in the collection const countOfAll = await execute(db.pipeline() .collection("books") .aggregate(countAll().as("count")) ); // Number of books with nonnull `ratings` field const countField = await execute(db.pipeline() .collection("books") .aggregate(field("ratings").count().as("count")) );
Swift
// Total number of books in the collection let countAll = try await db.pipeline() .collection("books") .aggregate([CountAll().as("count")]) .execute() // Number of books with nonnull `ratings` field let countField = try await db.pipeline() .collection("books") .aggregate([Field("ratings").count().as("count")]) .execute()
Kotlin
// Total number of books in the collection val countAll = db.pipeline() .collection("books") .aggregate(AggregateFunction.countAll().alias("count")) .execute() // Number of books with nonnull `ratings` field val countField = db.pipeline() .collection("books") .aggregate(AggregateFunction.count("ratings").alias("count")) .execute()
Java
// Total number of books in the collection Task<Pipeline.Snapshot> countAll = db.pipeline() .collection("books") .aggregate(AggregateFunction.countAll().alias("count")) .execute(); // Number of books with nonnull `ratings` field Task<Pipeline.Snapshot> countField = db.pipeline() .collection("books") .aggregate(AggregateFunction.count("ratings").alias("count")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Count # Total number of books in the collection count_all = ( client.pipeline().collection("books").aggregate(Count().as_("count")).execute() ) # Number of books with nonnull `ratings` field count_field = ( client.pipeline() .collection("books") .aggregate(Count("ratings").as_("count")) .execute() )
Java
// Total number of books in the collection Pipeline.Snapshot countAll = firestore.pipeline().collection("books").aggregate(countAll().as("count")).execute().get(); // Number of books with nonnull `ratings` field Pipeline.Snapshot countField = firestore .pipeline() .collection("books") .aggregate(count("ratings").as("count")) .execute() .get();
COUNT_IF
Söz dizimi:
count_if(expression: BOOLEAN) -> INT64
Açıklama:
expression ifadesinin TRUE olarak değerlendirildiği önceki aşamadaki belge sayısını döndürür.
Node.js
const result = await db.pipeline() .collection("books") .aggregate( field("rating").greaterThan(4).countIf().as("filteredCount") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate( field("rating").greaterThan(4).countIf().as("filteredCount") ) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([ AggregateFunction("count_if", [Field("rating").greaterThan(4)]).as("filteredCount") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate( AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate( AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("rating").greater_than(4).count_if().as_("filteredCount")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countIf(field("rating").greaterThan(4)).as("filteredCount")) .execute() .get();
COUNT_DISTINCT
Söz dizimi:
count_distinct(expression: ANY) -> INT64
Açıklama:
expression değerinin benzersiz, NULL olmayan ve ABSENT olmayan değerlerinin sayısını döndürür.
Node.js
const result = await db.pipeline() .collection("books") .aggregate(field("author").countDistinct().as("unique_authors")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("author").countDistinct().as("unique_authors")) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([AggregateFunction("count_distinct", [Field("author")]).as("unique_authors")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("author").count_distinct().as_("unique_authors")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(countDistinct("author").as("unique_authors")) .execute() .get();
TOPLA
Söz dizimi:
sum(expression: ANY) -> NUMBER
Açıklama:
Sayısal olmayan değerleri yoksayarak tüm sayısal değerlerin toplamını döndürür. Değerlerden herhangi biri NaN ise NaN değerini döndürür.
Çıkış, aşağıdaki durumlar hariç en geniş giriş türüyle aynı türde olur:
INTEGERolarak gösterilemeyen birINTEGER,DOUBLE'ye dönüştürülür.
Node.js
const result = await db.pipeline() .collection("cities") .aggregate(field("population").sum().as("totalPopulation")) .execute();
Web
const result = await execute(db.pipeline() .collection("cities") .aggregate(field("population").sum().as("totalPopulation")) );
Swift
let result = try await db.pipeline() .collection("cities") .aggregate([Field("population").sum().as("totalPopulation")]) .execute()
Kotlin
val result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.sum("population").alias("totalPopulation")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.sum("population").alias("totalPopulation")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("cities") .aggregate(Field.of("population").sum().as_("totalPopulation")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(sum("population").as("totalPopulation")) .execute() .get();
ORTALAMA
Söz dizimi:
average(expression: ANY) -> FLOAT64
Açıklama:
Sayısal olmayan değerleri yoksayarak tüm sayısal değerlerin ortalamasını döndürür.
Değerlerden herhangi biri NaN ise NaN, sayısal değerler toplanmamışsa NULL olarak değerlendirilir.
Çıkış, aşağıdaki durumlar hariç giriş türüyle aynı türde olur:
INTEGERolarak gösterilemeyen birINTEGER,DOUBLE'ye dönüştürülür.
Node.js
const result = await db.pipeline() .collection("cities") .aggregate(field("population").average().as("averagePopulation")) .execute();
Web
const result = await execute(db.pipeline() .collection("cities") .aggregate(field("population").average().as("averagePopulation")) );
Swift
let result = try await db.pipeline() .collection("cities") .aggregate([Field("population").average().as("averagePopulation")]) .execute()
Kotlin
val result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.average("population").alias("averagePopulation")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("cities") .aggregate(AggregateFunction.average("population").alias("averagePopulation")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("cities") .aggregate(Field.of("population").average().as_("averagePopulation")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("cities") .aggregate(average("population").as("averagePopulation")) .execute() .get();
MİNİMUM
Söz dizimi:
minimum(expression: ANY) -> ANY
Açıklama:
Her belgede değerlendirildiğinde NULL olmayan ve mevcut olmayan expression değerinin minimum değerini döndürür.
NULL olmayan ve eksik olmayan değer yoksa NULL döndürülür. Hiçbir belgenin dikkate alınmadığı durumlar da buna dahildir.
Birden fazla minimum eşdeğer değer varsa bu değerlerden herhangi biri döndürülebilir. Değer türü sıralaması, belgelenen sıralamaya göre yapılır.
Node.js
const result = await db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([Field("price").minimum().as("minimumPrice")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.minimum("price").alias("minimumPrice")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.minimum("price").alias("minimumPrice")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("price").minimum().as_("minimumPrice")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(minimum("price").as("minimumPrice")) .execute() .get();
MAKSİMUM
Söz dizimi:
maximum(expression: ANY) -> ANY
Açıklama:
Her belgede değerlendirildiğinde expression öğesinin maksimum NULL olmayan, eksik olmayan değerini döndürür.
NULL olmayan ve eksik olmayan değer yoksa NULL döndürülür. Hiçbir belgenin dikkate alınmadığı durumlar da buna dahildir.
Birden fazla maksimum eşdeğer değer varsa bu değerlerden herhangi biri döndürülebilir. Değer türü sıralaması, belgelenen sıralamaya göre yapılır.
Node.js
const result = await db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .aggregate([Field("price").maximum().as("maximumPrice")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .aggregate(AggregateFunction.maximum("price").alias("maximumPrice")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .aggregate(AggregateFunction.maximum("price").alias("maximumPrice")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .aggregate(Field.of("price").maximum().as_("maximumPrice")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .aggregate(maximum("price").as("maximumPrice")) .execute() .get();
FIRST
Söz dizimi:
first(expression: ANY) -> ANY
Açıklama:
Döndürülen ilk doküman için expression değerini döndürür.
SON
Söz dizimi:
last(expression: ANY) -> ANY
Açıklama:
Son döndürülen doküman için expression değerini döndürür.
ARRAY_AGG
Söz dizimi:
array_agg(expression: ANY) -> ARRAY<ANY>
Açıklama:
Her belgede değerlendirildiğinde expression değerlerinin tümünü içeren bir dizi döndürür.
İfade, mevcut olmayan bir değere çözümlenirse NULL değerine dönüştürülür.
Çıkış dizisindeki öğelerin sırası sabit değildir ve bu sıraya güvenilmemelidir.
ARRAY_AGG_DISTINCT
Söz dizimi:
array_agg_distinct(expression: ANY) -> ARRAY<ANY>
Açıklama:
Her belgede değerlendirildiğinde expression öğesinin tüm farklı değerlerini içeren bir dizi döndürür.
İfade, mevcut olmayan bir değere çözümlenirse NULL değerine dönüştürülür.
Çıkış dizisindeki öğelerin sırası sabit değildir ve bu sıraya güvenilmemelidir.