الدوال المنطقية
| الاسم | الوصف |
AND
|
تنفّذ هذه الدالة عملية AND منطقية |
OR
|
تنفّذ عملية "أو" منطقية |
XOR
|
تنفّذ هذه الدالة عملية XOR منطقية |
NOT
|
تنفّذ عملية NOT منطقية |
NOR
|
تنفّذ هذه الدالة عملية NOR منطقية |
CONDITIONAL
|
يتم تقييم الفروع استنادًا إلى تعبير شرطي. |
IF_NULL
|
تعرض أول قيمة غير فارغة |
SWITCH_ON
|
تقييم الفروع استنادًا إلى سلسلة من الشروط |
EQUAL_ANY
|
تتحقّق هذه الدالة مما إذا كانت قيمة معيّنة تساوي أي عناصر في مصفوفة |
NOT_EQUAL_ANY
|
تتحقّق هذه الدالة مما إذا كانت قيمة معيّنة لا تساوي أي عنصر في مصفوفة |
MAXIMUM
|
تعرض القيمة القصوى في مجموعة من القيم |
MINIMUM
|
تعرض هذه الدالة الحد الأدنى للقيمة في مجموعة من القيم |
و
البنية:
and(x: BOOLEAN...) -> BOOLEAN
الوصف:
تعرض هذه الدالة القيمة المنطقية AND لقيمتَين منطقيتَين أو أكثر.
تعرض الدالة NULL إذا تعذّر اشتقاق النتيجة بسبب أنّ أيًا من القيم المحدّدة هي ABSENT أو NULL.
أمثلة:
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
val result = db.pipeline() .collection("books") .select( Expression.and(field("rating").greaterThan(4), field("price").lessThan(10)) .alias("under10Recommendation") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.And( firestore.GreaterThan(firestore.FieldOf("rating"), 4), firestore.LessThan(firestore.FieldOf("price"), 10), ).As("under10Recommendation"), )). Execute(ctx)
أو
البنية:
or(x: BOOLEAN...) -> BOOLEAN
الوصف:
لعرض القيمة المنطقية OR لقيمتَين منطقيتَين أو أكثر.
تعرض الدالة NULL إذا تعذّر اشتقاق النتيجة بسبب أنّ أيًا من القيم المحدّدة هي ABSENT أو NULL.
أمثلة:
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
val result = db.pipeline() .collection("books") .select( Expression.or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure")) .alias("matchesSearchFilters") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Or( firestore.Equal(firestore.FieldOf("genre"), "Fantasy"), firestore.ArrayContains(firestore.FieldOf("tags"), "adventure"), ).As("matchesSearchFilters"), )). Execute(ctx)
XOR
البنية:
xor(x: BOOLEAN...) -> BOOLEAN
الوصف:
لعرض القيمة المنطقية XOR لقيمتَين منطقيتَين أو أكثر.
تعرض هذه الدالة NULL إذا كانت أي من القيم المحدّدة هي ABSENT أو NULL.
أمثلة:
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
val result = db.pipeline() .collection("books") .select( Expression.xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction")) .alias("matchesSearchFilters") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Xor( firestore.ArrayContains(firestore.FieldOf("tags"), "magic"), firestore.ArrayContains(firestore.FieldOf("tags"), "nonfiction"), ).As("matchesSearchFilters"), )). Execute(ctx)
NOR
البنية:
nor(x: BOOLEAN...) -> BOOLEAN
الوصف:
لعرض القيمة المنطقية NOR لقيمتَين منطقيتَين أو أكثر.
تعرض الدالة NULL إذا تعذّر اشتقاق النتيجة بسبب أنّ أيًا من القيم المحدّدة هي ABSENT أو NULL.
أمثلة:
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
البنية:
not(x: BOOLEAN) -> BOOLEAN
الوصف:
لعرض القيمة المنطقية NOT لقيمة منطقية.
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
val result = db.pipeline() .collection("books") .select( Expression.not( field("tags").arrayContains("nonfiction") ).alias("isFiction") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.Not(firestore.ArrayContains(firestore.FieldOf("tags"), "nonfiction")).As("isFiction"), )). Execute(ctx)
CONDITIONAL
البنية:
conditional(condition: BOOLEAN, true_case: ANY, false_case: ANY) -> ANY
الوصف:
تقيّم هذه الدالة true_case وتعرضها إذا كان تقييم condition هو TRUE.
تقيّم هذه الدالة false_case وتعرضها إذا كانت نتيجة الشرط FALSE أو NULL أو قيمة ABSENT.
أمثلة:
condition |
true_case |
false_case |
conditional(condition, true_case, false_case) |
|---|---|---|---|
TRUE |
1 لتر | 0 لتر | 1 لتر |
FALSE |
1 لتر | 0 لتر | 0 لتر |
NULL |
1 لتر | 0 لتر | 0 لتر |
ABSENT |
1 لتر | 0 لتر | 0 لتر |
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
val result = db.pipeline() .collection("books") .select( field("tags").arrayConcat( Expression.conditional( field("pages").greaterThan(100), constant("longRead"), constant("shortRead") ) ).alias("extendedTags") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.ArrayConcat( firestore.FieldOf("tags"), firestore.Conditional( firestore.GreaterThan(firestore.FieldOf("pages"), 100), firestore.ConstantOf("longRead"), firestore.ConstantOf("shortRead"), ), ).As("extendedTags"), )). Execute(ctx)
IF_NULL
البنية:
if_null(expr: ANY, replacement: ANY) -> ANY
الوصف:
تعرض هذه الدالة expr إذا لم تكن NULL، وإلا فإنها تقيّم replacement وتعرضها. لا يتم تقييم التعبير replacement في حال استخدام expr.
أمثلة:
expr |
replacement |
if_null(expr, replacement) |
|---|---|---|
| 1 لتر | 2 لتر | 1 لتر |
NULL |
2 لتر | 2 لتر |
ABSENT |
2 لتر | ABSENT |
SWITCH_ON
البنية:
switch_on(cond1: BOOLEAN, res1: ANY, cond2: BOOLEAN, res2: ANY, ..., [default: ANY]) -> ANY
الوصف:
تقيّم هذه الدالة سلسلة من الشروط وتعرض النتيجة المرتبطة بالشرط الأول الذي تكون قيمته TRUE. إذا لم يتم تقييم أي شروط على أنّها TRUE، يتم عرض القيمة default إذا تم توفيرها. في حال عدم تقديم قيمة default، يتم عرض خطأ إذا لم يتم تقييم أي شروط أخرى على أنّها TRUE.
لتقديم قيمة default، يجب تمريرها كوسيطة نهائية بحيث يكون هناك
عدد فردي من الوسيطات.
أمثلة:
x |
switch_on(eq(x, 1L), "one", eq(x, 2L), "two", "other") |
|---|---|
| 1 لتر | "one" |
| 2 لتر | "two" |
| 3L | "other" |
EQUAL_ANY
البنية:
equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
الوصف:
تعرض هذه الدالة TRUE إذا كانت value في مصفوفة search_space.
أمثلة:
value |
search_space |
equal_any(value, search_space) |
|---|---|---|
| 0 لتر | [1L, 2L, 3L] | FALSE |
| 2 لتر | [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
val result = db.pipeline() .collection("books") .select( field("genre").equalAny(listOf("Science Fiction", "Psychological Thriller")) .alias("matchesGenreFilters") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.EqualAny(firestore.FieldOf("genre"), []string{"Science Fiction", "Psychological Thriller"}).As("matchesGenreFilters"), )). Execute(ctx)
NOT_EQUAL_ANY
البنية:
not_equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN
الوصف:
تعرض الدالة TRUE إذا لم تكن value في مصفوفة search_space.
أمثلة:
value |
search_space |
not_equal_any(value, search_space) |
|---|---|---|
| 0 لتر | [1L, 2L, 3L] | TRUE |
| 2 لتر | [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
val result = db.pipeline() .collection("books") .select( field("author").notEqualAny(listOf("George Orwell", "F. Scott Fitzgerald")) .alias("byExcludedAuthors") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.NotEqualAny(firestore.FieldOf("author"), []string{"George Orwell", "F. Scott Fitzgerald"}).As("byExcludedAuthors"), )). Execute(ctx)
الحد الأقصى
البنية:
maximum(x: ANY...) -> ANY
maximum(x: ARRAY) -> ANY
الوصف:
لعرض الحد الأقصى للقيمة غير NULL وغير ABSENT في سلسلة من القيم x.
إذا لم تكن هناك قيم غير NULL وغير ABSENT، يتم عرض NULL.
في حال توفّر قيم قصوى متكافئة متعددة، يمكن عرض أيّ منها. يتبع ترتيب نوع القيمة الترتيب الموثَّق.
أمثلة:
x |
y |
maximum(x, y) |
|---|---|---|
FALSE |
TRUE |
TRUE |
FALSE |
-10 لتر | -10 لتر |
| 0.0 | -5 لتر | 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
val result = db.pipeline() .collection("books") .select( field("rating").logicalMaximum(1).alias("flooredRating") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.LogicalMaximum(firestore.FieldOf("rating"), 1).As("flooredRating"), )). Execute(ctx)
الحد الأدنى
البنية:
minimum(x: ANY...) -> ANY
minimum(x: ARRAY) -> ANY
الوصف:
تعرض الحد الأدنى للقيمة غير NULL وغير ABSENT في سلسلة من القيم x.
إذا لم تكن هناك قيم غير NULL وغير ABSENT، يتم عرض NULL.
إذا كانت هناك قيم دنيا متكافئة متعددة، يمكن عرض أي من هذه القيم. يتبع ترتيب نوع القيمة الترتيب الموثَّق.
أمثلة:
x |
y |
minimum(x, y) |
|---|---|---|
FALSE |
TRUE |
FALSE |
FALSE |
-10 لتر | FALSE |
| 0.0 | -5 لتر | -5 لتر |
| "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
val result = db.pipeline() .collection("books") .select( field("rating").logicalMinimum(5).alias("cappedRating") ) .execute()
Java
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();
متابعة
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.LogicalMinimum(firestore.FieldOf("rating"), 5).As("cappedRating"), )). Execute(ctx)