Referenz zu logischen Funktionen
Logische Funktionen
| Name | Beschreibung |
AND
|
Führt ein logisches UND aus |
OR
|
Führt ein logisches ODER aus |
XOR
|
Führt eine logische XOR-Operation aus |
NOT
|
Führt ein logisches NICHT aus |
NOR
|
Führt ein logisches NOR aus |
CONDITIONAL
|
Verzweigt die Auswertung basierend auf einem Bedingungsausdruck. |
IF_NULL
|
Gibt den ersten Nicht-Null-Wert zurück. |
SWITCH_ON
|
Verzweigungen basierend auf einer Reihe von Bedingungen auswerten |
EQUAL_ANY
|
Prüft, ob ein Wert mit einem Element in einem Array übereinstimmt |
NOT_EQUAL_ANY
|
Prüft, ob ein Wert nicht mit einem Element in einem Array übereinstimmt |
MAXIMUM
|
Gibt den Maximalwert in einer Gruppe von Werten zurück. |
MINIMUM
|
Gibt den Minimalwert in einer Gruppe von Werten zurück |
UND
Syntax:
and(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische UND von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn das Ergebnis nicht abgeleitet werden kann, weil einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
x |
y |
and(x, y) |
|---|---|---|
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
NULL |
TRUE |
NULL |
ABSENT |
TRUE |
NULL |
NULL |
FALSE |
FALSE |
FALSE |
ABSENT |
FALSE |
Node.js
const result = await db.pipeline() .collection("books") .select( and(field("rating").greaterThan(4), field("price").lessThan(10)) .as("under10Recommendation") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( and(field("rating").greaterThan(4), field("price").lessThan(10)) .as("under10Recommendation") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (Field("rating").greaterThan(4) && Field("price").lessThan(10)) .as("under10Recommendation") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( Expression.and(field("rating").greaterThan(4), field("price").lessThan(10)) .alias("under10Recommendation") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.and( field("rating").greaterThan(4), field("price").lessThan(10) ).alias("under10Recommendation") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, And result = ( client.pipeline() .collection("books") .select( And( Field.of("rating").greater_than(4), Field.of("price").less_than(10) ).as_("under10Recommendation") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( and(greaterThan(field("rating"), 4), lessThan(field("price"), 10)) .as("under10Recommendation")) .execute() .get();
ODER
Syntax:
or(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische ODER von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn das Ergebnis nicht abgeleitet werden kann, weil einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
x |
y |
or(x, y) |
|---|---|---|
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
TRUE |
NULL |
TRUE |
TRUE |
ABSENT |
TRUE |
TRUE |
NULL |
FALSE |
NULL |
FALSE |
ABSENT |
NULL |
Node.js
const result = await db.pipeline() .collection("books") .select( or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .as("matchesSearchFilters") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .as("matchesSearchFilters") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (Field("genre").equal("Fantasy") || Field("tags").arrayContains("adventure")) .as("matchesSearchFilters") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( Expression.or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .alias("matchesSearchFilters") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.or( field("genre").equal("Fantasy"), field("tags").arrayContains("adventure") ).alias("matchesSearchFilters") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, And, Or result = ( client.pipeline() .collection("books") .select( Or( Field.of("genre").equal("Fantasy"), Field.of("tags").array_contains("adventure"), ).as_("matchesSearchFilters") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( or(equal(field("genre"), "Fantasy"), arrayContains(field("tags"), "adventure")) .as("matchesSearchFilters")) .execute() .get();
XOR
Syntax:
xor(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische XOR von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
x |
y |
xor(x, y) |
|---|---|---|
TRUE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
TRUE |
NULL |
TRUE |
NULL |
ABSENT |
TRUE |
NULL |
NULL |
FALSE |
NULL |
FALSE |
ABSENT |
NULL |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .as("matchesSearchFilters") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .as("matchesSearchFilters") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (Field("tags").arrayContains("magic") ^ Field("tags").arrayContains("nonfiction")) .as("matchesSearchFilters") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( Expression.xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .alias("matchesSearchFilters") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.xor( field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction") ).alias("matchesSearchFilters") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, Xor result = ( client.pipeline() .collection("books") .select( Xor( [ Field.of("tags").array_contains("magic"), Field.of("tags").array_contains("nonfiction"), ] ).as_("matchesSearchFilters") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( xor( arrayContains(field("tags"), "magic"), arrayContains(field("tags"), "nonfiction")) .as("matchesSearchFilters")) .execute() .get();
NOR
Syntax:
nor(x: BOOLEAN...) -> BOOLEAN
Beschreibung:
Gibt das logische NOR von zwei oder mehr booleschen Werten zurück.
Gibt NULL zurück, wenn das Ergebnis nicht abgeleitet werden kann, weil einer der angegebenen Werte ABSENT oder NULL ist.
Beispiele:
x |
y |
nor(x, y) |
|---|---|---|
TRUE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
TRUE |
NULL |
TRUE |
FALSE |
ABSENT |
TRUE |
FALSE |
NULL |
FALSE |
NULL |
FALSE |
ABSENT |
NULL |
NOT
Syntax:
not(x: BOOLEAN) -> BOOLEAN
Beschreibung:
Gibt den logischen NICHT-Wert eines booleschen Werts zurück.
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayContains("nonfiction").not() .as("isFiction") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayContains("nonfiction").not() .as("isFiction") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ (!Field("tags").arrayContains("nonfiction")) .as("isFiction") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( Expression.not( field("tags").arrayContains("nonfiction") ).alias("isFiction") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( Expression.not( field("tags").arrayContains("nonfiction") ).alias("isFiction") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field, Not result = ( client.pipeline() .collection("books") .select(Not(Field.of("tags").array_contains("nonfiction")).as_("isFiction")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(not(arrayContains(field("tags"), "nonfiction")).as("isFiction")) .execute() .get();
BEDINGT
Syntax:
conditional(condition: BOOLEAN, true_case: ANY, false_case: ANY) -> ANY
Beschreibung:
Wertet true_case aus und gibt es zurück, wenn condition als TRUE ausgewertet wird.
Wertet false_case aus und gibt es zurück, wenn die Bedingung zu FALSE, NULL oder einem ABSENT-Wert aufgelöst wird.
Beispiele:
condition |
true_case |
false_case |
conditional(condition, true_case, false_case) |
|---|---|---|---|
TRUE |
1L | 0L | 1L |
FALSE |
1L | 0L | 0L |
NULL |
1L | 0L | 0L |
ABSENT |
1L | 0L | 0L |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayConcat([ field("pages").greaterThan(100) .conditional(constant("longRead"), constant("shortRead")) ]).as("extendedTags") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("tags").arrayConcat([ field("pages").greaterThan(100) .conditional(constant("longRead"), constant("shortRead")) ]).as("extendedTags") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("tags").arrayConcat([ ConditionalExpression( Field("pages").greaterThan(100), then: Constant("longRead"), else: Constant("shortRead") ) ]).as("extendedTags") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("tags").arrayConcat( Expression.conditional( field("pages").greaterThan(100), constant("longRead"), constant("shortRead") ) ).alias("extendedTags") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("tags").arrayConcat( Expression.conditional( field("pages").greaterThan(100), constant("longRead"), constant("shortRead") ) ).alias("extendedTags") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import ( Field, Constant, Conditional, ) result = ( client.pipeline() .collection("books") .select( Field.of("tags") .array_concat( Conditional( Field.of("pages").greater_than(100), Constant.of("longRead"), Constant.of("shortRead"), ) ) .as_("extendedTags") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( arrayConcat( field("tags"), conditional( greaterThan(field("pages"), 100), constant("longRead"), constant("shortRead"))) .as("extendedTags")) .execute() .get();
IF_NULL
Syntax:
if_null(expr: ANY, replacement: ANY) -> ANY
Beschreibung:
Gibt expr zurück, wenn es nicht NULL ist. Andernfalls wird replacement ausgewertet und zurückgegeben. Der Ausdruck replacement wird nicht ausgewertet, wenn expr verwendet wird.
Beispiele:
expr |
replacement |
if_null(expr, replacement) |
|---|---|---|
| 1L | 2L | 1L |
NULL |
2L | 2L |
ABSENT |
2L | ABSENT |
SWITCH_ON
Syntax:
switch_on(cond1: BOOLEAN, res1: ANY, cond2: BOOLEAN, res2: ANY, ..., [default: ANY]) -> ANY
Beschreibung:
Wertet eine Reihe von Bedingungen aus und gibt das Ergebnis zurück, das der ersten TRUE-Bedingung zugeordnet ist. Wenn keine Bedingung als TRUE ausgewertet wird, wird der Wert default zurückgegeben, sofern er angegeben ist. Wenn kein default-Wert angegeben ist, wird ein Fehler ausgegeben, wenn keine anderen Bedingungen als TRUE ausgewertet werden.
Wenn Sie einen default-Wert angeben möchten, übergeben Sie ihn als letztes Argument, sodass eine ungerade Anzahl von Argumenten vorhanden ist.
Beispiele:
x |
switch_on(eq(x, 1L), "one", eq(x, 2L), "two", "other") |
|---|---|
| 1L | "eins" |
| 2L | "zwei" |
| 3L | „other“ |
EQUAL_ANY
Syntax:
equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value im Array search_space enthalten ist.
Beispiele:
value |
search_space |
equal_any(value, search_space) |
|---|---|---|
| 0L | [1L, 2L, 3L] | FALSE |
| 2L | [1L, 2L, 3L] | TRUE |
NULL |
[1L, 2L, 3L] | FALSE |
NULL |
[1L, NULL] |
TRUE |
ABSENT |
[1L, NULL] |
FALSE |
| NaN | [1L, NaN, 3L] | TRUE |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("genre").equalAny(["Science Fiction", "Psychological Thriller"]) .as("matchesGenreFilters") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("genre").equalAny(["Science Fiction", "Psychological Thriller"]) .as("matchesGenreFilters") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("genre").equalAny(["Science Fiction", "Psychological Thriller"]) .as("matchesGenreFilters") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("genre").equalAny(listOf("Science Fiction", "Psychological Thriller")) .alias("matchesGenreFilters") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("genre").equalAny(Arrays.asList("Science Fiction", "Psychological Thriller")) .alias("matchesGenreFilters") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("genre") .equal_any(["Science Fiction", "Psychological Thriller"]) .as_("matchesGenreFilters") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( equalAny(field("genre"), Arrays.asList("Science Fiction", "Psychological Thriller")) .as("matchesGenreFilters")) .execute() .get();
NOT_EQUAL_ANY
Syntax:
not_equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
Beschreibung:
Gibt TRUE zurück, wenn value nicht im Array search_space enthalten ist.
Beispiele:
value |
search_space |
not_equal_any(value, search_space) |
|---|---|---|
| 0L | [1L, 2L, 3L] | TRUE |
| 2L | [1L, 2L, 3L] | FALSE |
NULL |
[1L, 2L, 3L] | TRUE |
NULL |
[1L, NULL] |
FALSE |
ABSENT |
[1L, NULL] |
TRUE |
| NaN | [1L, NaN, 3L] | FALSE |
Node.js
const result = await execute(db.pipeline() .collection("books") .select( field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"]) .as("byExcludedAuthors") ) );
Web
const result = await execute(db.pipeline() .collection("books") .select( field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"]) .as("byExcludedAuthors") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"]) .as("byExcludedAuthors") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("author").notEqualAny(listOf("George Orwell", "F. Scott Fitzgerald")) .alias("byExcludedAuthors") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("author").notEqualAny(Arrays.asList("George Orwell", "F. Scott Fitzgerald")) .alias("byExcludedAuthors") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("author") .not_equal_any(["George Orwell", "F. Scott Fitzgerald"]) .as_("byExcludedAuthors") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select( notEqualAny(field("author"), Arrays.asList("George Orwell", "F. Scott Fitzgerald")) .as("byExcludedAuthors")) .execute() .get();
MAXIMUM
Syntax:
maximum(x: ANY...) -> ANY
maximum(x: ARRAY) -> ANY
Beschreibung:
Gibt den maximalen Wert ungleich NULL und ABSENT in einer Reihe von Werten x zurück.
Wenn es keine Werte gibt, die weder NULL noch ABSENT sind, wird NULL zurückgegeben.
Wenn es mehrere gleichwertige Maximalwerte gibt, kann ein beliebiger dieser Werte zurückgegeben werden. Die Werttypsortierung folgt der dokumentierten Sortierung.
Beispiele:
x |
y |
maximum(x, y) |
|---|---|---|
FALSE |
TRUE |
TRUE |
FALSE |
–10L | –10L |
| 0,0 | –5L | 0,0 |
| "foo" | "bar" | "foo" |
| "foo" | ["foo"] | ["foo"] |
ABSENT |
ABSENT |
NULL |
NULL |
NULL |
NULL |
Node.js
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").maximum().as("maximumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("rating").logicalMaximum([1]).as("flooredRating") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("rating").logicalMaximum(1).alias("flooredRating") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("rating").logicalMaximum(1).alias("flooredRating") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").logical_maximum(1).as_("flooredRating")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(logicalMaximum(field("rating"), 1).as("flooredRating")) .execute() .get();
MINIMUM
Syntax:
minimum(x: ANY...) -> ANY
minimum(x: ARRAY) -> ANY
Beschreibung:
Gibt den Mindestwert ungleich NULL und ABSENT in einer Reihe von Werten x zurück.
Wenn es keine Werte gibt, die weder NULL noch ABSENT sind, wird NULL zurückgegeben.
Wenn es mehrere gleichwertige Mindestwerte gibt, kann ein beliebiger dieser Werte zurückgegeben werden. Die Werttypsortierung folgt der dokumentierten Sortierung.
Beispiele:
x |
y |
minimum(x, y) |
|---|---|---|
FALSE |
TRUE |
FALSE |
FALSE |
–10L | FALSE |
| 0,0 | –5L | –5L |
| "foo" | "bar" | "bar" |
| "foo" | ["foo"] | "foo" |
ABSENT |
ABSENT |
NULL |
NULL |
NULL |
NULL |
Node.js
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
Web
const result = await execute(db.pipeline() .collection("books") .aggregate(field("price").minimum().as("minimumPrice")) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("rating").logicalMinimum([5]).as("cappedRating") ]) .execute()
Kotlin
Android
val result = db.pipeline() .collection("books") .select( field("rating").logicalMinimum(5).alias("cappedRating") ) .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("rating").logicalMinimum(5).alias("cappedRating") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("rating").logical_minimum(5).as_("cappedRating")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(logicalMinimum(field("rating"), 5).as("cappedRating")) .execute() .get();