Referencia de funciones de cadena

Funciones de string

Nombre Descripción
BYTE_LENGTH Devuelve la cantidad de BYTES en un valor de STRING o BYTES.
CHAR_LENGTH Devuelve la cantidad de caracteres Unicode en un valor STRING.
STARTS_WITH Devuelve TRUE si una STRING comienza con un prefijo determinado.
ENDS_WITH Devuelve TRUE si una STRING termina con un sufijo determinado.
LIKE Devuelve TRUE si una STRING coincide con un patrón.
REGEX_CONTAINS Devuelve TRUE si un valor coincide parcial o completamente con una expresión regular
REGEX_FIND Devuelve la primera subcadena que coincide con una expresión regular o NULL si no hay ninguna coincidencia.
REGEX_FIND_ALL Devuelve un array de todas las substrings que coinciden con una expresión regular o un array vacío si no hay coincidencias.
REGEX_MATCH Devuelve TRUE si alguna parte de un valor coincide con una expresión regular
STRING_CONCAT Concatena varias STRING en una sola STRING.
STRING_CONTAINS Devuelve TRUE si un valor contiene una STRING.
STRING_INDEX_OF Devuelve el índice basado en 0 de la primera ocurrencia de un valor de STRING o BYTES.
TO_UPPER Convierte un valor STRING o BYTES en mayúsculas.
TO_LOWER Convierte un valor STRING o BYTES en minúsculas.
SUBSTRING Obtiene una subcadena de un valor STRING o BYTES.
STRING_REVERSE Invierte un valor STRING o BYTES.
STRING_REPEAT Repite un valor STRING o BYTES una cantidad especificada de veces.
STRING_REPLACE_ALL Reemplaza todos los casos de un valor STRING o BYTES.
STRING_REPLACE_ONE Reemplaza la primera ocurrencia de un valor STRING o BYTES.
TRIM Recorta los caracteres iniciales y finales de un valor STRING o BYTES.
LTRIM Recorta los caracteres iniciales de un valor STRING o BYTES.
RTRIM Recorta los caracteres finales de un valor STRING o BYTES.
SPLIT Divide un valor STRING o BYTES en un array.

BYTE_LENGTH

Sintaxis:

byte_length[T <: STRING | BYTES](value: T) -> INT64

Descripción:

Devuelve la cantidad de BYTES en un valor STRING o BYTES.

Ejemplos:

valor byte_length(value)
"abc" 3
"xyzabc" 6
b"abc" 3
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").byteLength().as("titleByteLength")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").byteLength().as("titleByteLength")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").byteLength().as("titleByteLength")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("title").byteLength().alias("titleByteLength")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").byteLength().alias("titleByteLength")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").byte_length().as_("titleByteLength"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(byteLength(field("title")).as("titleByteLength"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.ByteLength(firestore.FieldOf("title")).As("titleByteLength"),
	)).
	Execute(ctx)

CHAR_LENGTH

Sintaxis:

char_length(value: STRING) -> INT64

Descripción:

Devuelve la cantidad de puntos de código Unicode en el valor de STRING.

Ejemplos:

valor char_length(value)
"abc" 3
"hello" 5
"world" 5
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").charLength().as("titleCharLength")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").charLength().as("titleCharLength")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").charLength().as("titleCharLength")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("title").charLength().alias("titleCharLength")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").charLength().alias("titleCharLength")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").char_length().as_("titleCharLength"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(charLength(field("title")).as("titleCharLength"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.CharLength(firestore.FieldOf("title")).As("titleCharLength"),
	)).
	Execute(ctx)

STARTS_WITH

Sintaxis:

starts_with(value: STRING, prefix: STRING) -> BOOLEAN

Descripción:

Devuelve TRUE si value comienza con prefix.

Ejemplos:

valor prefijo starts_with(value, prefix)
"abc" "a" verdadero
"abc" "b" falso
"abc" "" verdadero
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").startsWith("The")
      .as("needsSpecialAlphabeticalSort")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").startsWith("The")
      .as("needsSpecialAlphabeticalSort")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").startsWith("The")
      .as("needsSpecialAlphabeticalSort")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("title").startsWith("The")
            .alias("needsSpecialAlphabeticalSort")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").startsWith("The")
            .alias("needsSpecialAlphabeticalSort")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("title").starts_with("The").as_("needsSpecialAlphabeticalSort")
    )
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(startsWith(field("title"), "The").as("needsSpecialAlphabeticalSort"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.StartsWith(firestore.FieldOf("title"), "The").As("needsSpecialAlphabeticalSort"),
	)).
	Execute(ctx)

ENDS_WITH

Sintaxis:

ends_with(value: STRING, postfix: STRING) -> BOOLEAN

Descripción:

Devuelve TRUE si value termina con postfix.

Ejemplos:

valor postfix ends_with(value, postfix)
"abc" "c" verdadero
"abc" "b" falso
"abc" "" verdadero
Node.js
const result = await db.pipeline()
  .collection("inventory/devices/laptops")
  .select(
    field("name").endsWith("16 inch")
      .as("16InLaptops")
  )
  .execute();
Swift
let result = try await db.pipeline()
  .collection("inventory/devices/laptops")
  .select([
    Field("name").endsWith("16 inch")
      .as("16InLaptops")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("inventory/devices/laptops")
    .select(
        field("name").endsWith("16 inch")
            .alias("16InLaptops")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("inventory/devices/laptops")
    .select(
        field("name").endsWith("16 inch")
            .alias("16InLaptops")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("inventory/devices/laptops")
    .select(Field.of("name").ends_with("16 inch").as_("16InLaptops"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("inventory/devices/laptops")
        .select(endsWith(field("name"), "16 inch").as("16InLaptops"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("inventory/devices/laptops").
	Select(firestore.Fields(
		firestore.EndsWith(firestore.FieldOf("name"), "16 inch").As("`Laptops16in`"),
	)).
	Execute(ctx)

LIKE

Sintaxis:

like(value: STRING, pattern: STRING) -> BOOLEAN

Descripción:

Devuelve TRUE si value coincide con pattern.

Ejemplos:

valor patrón like(value, pattern)
"Firestore" "Fire%" verdadero
"Firestore" "%store" verdadero
"Datastore" "Data_tore" verdadero
"100%" "100\%" verdadero
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(
    field("genre").like("%Fiction")
      .as("anyFiction")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("genre").like("%Fiction")
      .as("anyFiction")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("genre").like("%Fiction")
      .as("anyFiction")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("genre").like("%Fiction")
            .alias("anyFiction")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("genre").like("%Fiction")
            .alias("anyFiction")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("genre").like("%Fiction").as_("anyFiction"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(like(field("genre"), "%Fiction").as("anyFiction"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.Like(firestore.FieldOf("genre"), "%Fiction").As("anyFiction"),
	)).
	Execute(ctx)

REGEX_CONTAINS

Sintaxis:

regex_contains(value: STRING, regexp: STRING | REGEX) -> BOOLEAN

Descripción:

Devuelve TRUE si alguna parte de value coincide con regexp. Si regexp no es una expresión regular válida, esta función devuelve un error.

El argumento regexp también puede ser un valor REGEX creado con regex("pattern", "options"). Este formato te permite proporcionar opciones de expresiones regulares junto con el patrón. Las opciones compatibles son las siguientes:

  • i: Coincidencia que no distingue mayúsculas de minúsculas.
  • m: Modo de varias líneas (^ y $ coinciden con el inicio o el final de las líneas).
  • s: Modo Dotall (. coincide con saltos de línea).

Si regexp es un STRING, no se aplican opciones además de las incorporadas en el patrón en sí (p.ej., (?i)).

Las expresiones regulares siguen la sintaxis de la biblioteca re2.

Ejemplos:

valor regexp regex_contains(value, regexp)
"Firestore" "Fire" verdadero
"Firestore" "store$" verdadero
"Firestore" "data" falso
"Firestore" regex("fire", "i") verdadero
"Firestore" regex("FIRE", "") falso
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("title").regexContains("Firestore (Enterprise|Standard)")
      .as("isFirestoreRelated")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("title").regexContains("Firestore (Enterprise|Standard)")
      .as("isFirestoreRelated")
  )
);
Swift
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("title").regexContains("Firestore (Enterprise|Standard)")
      .as("isFirestoreRelated")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexContains("Firestore (Enterprise|Standard)")
            .alias("isFirestoreRelated")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexContains("Firestore (Enterprise|Standard)")
            .alias("isFirestoreRelated")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("title")
        .regex_contains("Firestore (Enterprise|Standard)")
        .as_("isFirestoreRelated")
    )
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(
            regexContains(field("title"), "Firestore (Enterprise|Standard)")
                .as("isFirestoreRelated"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.RegexContains(firestore.FieldOf("title"), "Firestore (Enterprise|Standard)").As("isFirestoreRelated"),
	)).
	Execute(ctx)

REGEX_FIND

Sintaxis:

regex_find(value: STRING, regexp: STRING | REGEX) -> STRING

Descripción:

Devuelve la primera subcadena en value que coincide con regexp o NULL si no hay coincidencia. Si regexp no es una expresión regular válida, esta función devuelve un error.

El argumento regexp también puede ser un valor REGEX creado con regex("pattern", "options"). Este formato te permite proporcionar opciones de expresiones regulares junto con el patrón. Las opciones compatibles son las siguientes:

  • i: Coincidencia que no distingue mayúsculas de minúsculas.
  • m: Modo de varias líneas (^ y $ coinciden con el inicio o el final de las líneas).
  • s: Modo Dotall (. coincide con saltos de línea).

Si regexp es un STRING, no se aplican opciones además de las incorporadas en el patrón en sí (p.ej., (?i)).

Las expresiones regulares siguen la sintaxis de la biblioteca re2.

Ejemplos:

valor regexp regex_find(value, regexp)
"Sometext MATCH" "SomeText" "Sometext"
"Sometext MATCH" regex("match", "i") "MATCH"
"Sometext MATCH" regex("(match)", "i") "MATCH"
"Coincidencia de texto" regex("MATCH", "") null

REGEX_FIND_ALL

Sintaxis:

regex_find_all(value: STRING, regexp: STRING | REGEX) -> ARRAY<STRING>

Descripción:

Devuelve un array de todas las substrings en value que coinciden con regexp o un array vacío si no hay coincidencias. Si regexp no es una expresión regular válida, esta función devuelve un error.

El argumento regexp también puede ser un valor REGEX creado con regex("pattern", "options"). Este formato te permite proporcionar opciones de expresiones regulares junto con el patrón. Las opciones compatibles son las siguientes:

  • i: Coincidencia que no distingue mayúsculas de minúsculas.
  • m: Modo de varias líneas (^ y $ coinciden con el inicio o el final de las líneas).
  • s: Modo Dotall (. coincide con saltos de línea).

Si regexp es un STRING, no se aplican opciones además de las incorporadas en el patrón en sí (p.ej., (?i)).

Las expresiones regulares siguen la sintaxis de la biblioteca re2.

Ejemplos:

valor regexp regex_find_all(value, regexp)
"one two three two" “uno” ["one"]
"one TWO three Two" regex("two", "i") ["TWO", "Two"]
"one two three two" regex("TWO", "") []

REGEX_MATCH

Sintaxis:

regex_match(value: STRING, regexp: STRING | REGEX) -> BOOLEAN

Descripción:

Devuelve TRUE si value coincide por completo con regexp. Si regexp no es una expresión regular válida, esta función devuelve un error.

El argumento regexp también puede ser un valor REGEX creado con regex("pattern", "options"). Este formato te permite proporcionar opciones de expresiones regulares junto con el patrón. Las opciones compatibles son las siguientes:

  • i: Coincidencia que no distingue mayúsculas de minúsculas.
  • m: Modo de varias líneas (^ y $ coinciden con el inicio o el final de las líneas).
  • s: Modo Dotall (. coincide con saltos de línea).

Si regexp es un STRING, no se aplican opciones además de las incorporadas en el patrón en sí (p.ej., (?i)).

Las expresiones regulares siguen la sintaxis de la biblioteca re2.

Ejemplos:

valor regexp regex_match(value, regexp)
"Firestore" "F.*store" verdadero
"Firestore" "Fire" falso
"Firestore" "^F.*e$" verdadero
"FiReStOrE" regex("firestore", "i") verdadero
"Firestore" regex("firestore", "") falso
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("title").regexMatch("Firestore (Enterprise|Standard)")
      .as("isFirestoreExactly")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("title").regexMatch("Firestore (Enterprise|Standard)")
      .as("isFirestoreExactly")
  )
);
Swift
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("title").regexMatch("Firestore (Enterprise|Standard)")
      .as("isFirestoreExactly")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexMatch("Firestore (Enterprise|Standard)")
            .alias("isFirestoreExactly")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexMatch("Firestore (Enterprise|Standard)")
            .alias("isFirestoreExactly")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("title")
        .regex_match("Firestore (Enterprise|Standard)")
        .as_("isFirestoreExactly")
    )
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(
            regexMatch(field("title"), "Firestore (Enterprise|Standard)")
                .as("isFirestoreExactly"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.RegexMatch(firestore.FieldOf("title"), "Firestore (Enterprise|Standard)").As("isFirestoreExactly"),
	)).
	Execute(ctx)

STRING_CONCAT

Sintaxis:

string_concat(values: STRING...) -> STRING

Descripción:

Concatena uno o más valores STRING en un solo resultado.

Ejemplos:

argumentos string_concat(values...)
() error
("a") "a"
("abc", "def") "abcdef"
("a", "", "c") "ac"
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").stringConcat(" by ", field("author"))
      .as("fullyQualifiedTitle")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").stringConcat(" by ", field("author"))
      .as("fullyQualifiedTitle")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").concat([" by ", Field("author")])
      .as("fullyQualifiedTitle")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("title").concat(" by ", field("author"))
            .alias("fullyQualifiedTitle")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").concat(" by ", field("author"))
            .alias("fullyQualifiedTitle")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("title")
        .concat(" by ", Field.of("author"))
        .as_("fullyQualifiedTitle")
    )
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(stringConcat(field("title"), " by ", field("author")).as("fullyQualifiedTitle"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.StringConcat(firestore.FieldOf("title"), " by ", firestore.FieldOf("author")).As("fullyQualifiedTitle"),
	)).
	Execute(ctx)

STRING_CONTAINS

Sintaxis:

string_contains(value: STRING, substring: STRING) -> BOOLEAN

Descripción:

Comprueba si value contiene la cadena literal substring.

Ejemplos:

valor subcadena string_contains(value, substring)
"abc" "b" verdadero
"abc" "d" falso
"abc" "" verdadero
"a.c" "." verdadero
"☃☃☃" "☃" verdadero
Node.js
const result = await db.pipeline()
  .collection("articles")
  .select(
    field("body").stringContains("Firestore")
      .as("isFirestoreRelated")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("articles")
  .select(
    field("body").stringContains("Firestore")
      .as("isFirestoreRelated")
  )
);
Swift
let result = try await db.pipeline()
  .collection("articles")
  .select([
    Field("body").stringContains("Firestore")
      .as("isFirestoreRelated")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("articles")
    .select(
        field("body").stringContains("Firestore")
            .alias("isFirestoreRelated")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("articles")
    .select(
        field("body").stringContains("Firestore")
            .alias("isFirestoreRelated")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("articles")
    .select(Field.of("body").string_contains("Firestore").as_("isFirestoreRelated"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("articles")
        .select(stringContains(field("body"), "Firestore").as("isFirestoreRelated"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("articles").
	Select(firestore.Fields(
		firestore.StringContains(firestore.FieldOf("body"), "Firestore").As("isFirestoreRelated"),
	)).
	Execute(ctx)

STRING_INDEX_OF

Sintaxis:

string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64

Descripción:

Devuelve el índice basado en 0 del primer caso de search en value.

  • Muestra -1 si no se encuentra search.
  • Si value es un valor de STRING, el resultado se mide en puntos de código Unicode. Si es un valor BYTES, se mide en bytes.
  • Si search es un valor de STRING o BYTES vacío, el resultado es 0.

Ejemplos:

valor search string_index_of(value, search)
"hello world" "o" 4
"hello world" "l" 2
"hello world" "z" -1
"banana" "ana" 1
"abc" "" 0
b"abc" b"b" 1
"é" "é" 0
b"é" b"é" 0

TO_UPPER

Sintaxis:

to_upper[T <: STRING | BYTES](value: T) -> T

Descripción:

Convierte un valor STRING o BYTES en mayúsculas.

Si un byte o un char no corresponde a un carácter alfabético en minúscula UTF-8, se pasa sin cambios.

Ejemplos:

valor to_upper(value)
"abc" "ABC"
"AbC" "ABC"
b"abc" b"ABC"
b"a1c" b"A1C"
Node.js
const result = await db.pipeline()
  .collection("authors")
  .select(
    field("name").toUpper()
      .as("uppercaseName")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("authors")
  .select(
    field("name").toUpper()
      .as("uppercaseName")
  )
);
Swift
let result = try await db.pipeline()
  .collection("authors")
  .select([
    Field("name").toUpper()
      .as("uppercaseName")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("authors")
    .select(
        field("name").toUpper()
            .alias("uppercaseName")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("authors")
    .select(
        field("name").toUpper()
            .alias("uppercaseName")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("authors")
    .select(Field.of("name").to_upper().as_("uppercaseName"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("authors")
        .select(toUpper(field("name")).as("uppercaseName"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("authors").
	Select(firestore.Fields(
		firestore.ToUpper(firestore.FieldOf("name")).As("uppercaseName"),
	)).
	Execute(ctx)

TO_LOWER

Sintaxis:

to_lower[T <: STRING | BYTES](value: T) -> T

Descripción:

Convierte un valor STRING o BYTES en minúsculas.

Si un byte o un char no corresponde a un carácter alfabético en mayúsculas UTF-8, se pasa sin cambios.

Ejemplos:

valor to_lower(value)
"ABC" "abc"
"AbC" "abc"
"A1C" "a1c"
b"ABC" b"abc"
Node.js
const result = await db.pipeline()
  .collection("authors")
  .select(
    field("genre").toLower().equal("fantasy")
      .as("isFantasy")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("authors")
  .select(
    field("genre").toLower().equal("fantasy")
      .as("isFantasy")
  )
);
Swift
let result = try await db.pipeline()
  .collection("authors")
  .select([
    Field("genre").toLower().equal("fantasy")
      .as("isFantasy")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("authors")
    .select(
        field("genre").toLower().equal("fantasy")
            .alias("isFantasy")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("authors")
    .select(
        field("genre").toLower().equal("fantasy")
            .alias("isFantasy")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("authors")
    .select(Field.of("genre").to_lower().equal("fantasy").as_("isFantasy"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("authors")
        .select(equal(toLower(field("genre")), "fantasy").as("isFantasy"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("authors").
	Select(firestore.Fields(
		firestore.Equal(firestore.ToLower(firestore.FieldOf("genre")), "fantasy").As("isFantasy"),
	)).
	Execute(ctx)

SUBSTRING

Sintaxis:

substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T

Descripción:

Devuelve una subcadena de input que comienza en position (índice basado en cero) y que incluye hasta entradas length. Si no se proporciona ningún length, devuelve la subcadena desde position hasta el final de input.

  • Si input es un valor de STRING, position y length se miden en puntos de código Unicode. Si es un valor BYTES, se miden en bytes.

  • Si position es mayor que la longitud de input, se devuelve una subcadena vacía. Si position más length es mayor que la longitud de input, la substring se trunca hasta el final de input.

  • Si position es negativo, la posición se toma desde el final de la entrada. Si la position negativa es mayor que el tamaño de la entrada, la posición se establece en cero. length no debe ser un valor negativo.

Ejemplos:

Cuando no se proporciona length:

entrada posición substring(input, position)
"abc" 0 "abc"
"abc" 1 "bc"
"abc" 3 ""
"abc" -1 "c"
b"abc" 1 b"bc"

Cuando se proporciona length, ocurre lo siguiente:

entrada posición longitud substring(input, position, length)
"abc" 0 1 "a"
"abc" 1 2 "bc"
"abc" -1 1 "c"
b"abc" 0 1 b"a"
Node.js
const result = await db.pipeline()
  .collection("books")
  .where(field("title").startsWith("The "))
  .select(
    field("title").substring(4)
      .as("titleWithoutLeadingThe")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .where(field("title").startsWith("The "))
  .select(
    field("title").substring(4)
      .as("titleWithoutLeadingThe")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .where(Field("title").startsWith("The "))
  .select([
    Field("title").substring(position: 4)
      .as("titleWithoutLeadingThe")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .where(field("title").startsWith("The "))
    .select(
        field("title")
          .substring(constant(4),
            field("title").charLength().subtract(4))
            .alias("titleWithoutLeadingThe")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .where(field("title").startsWith("The "))
    .select(
        field("title").substring(
          constant(4),
            field("title").charLength().subtract(4))
            .alias("titleWithoutLeadingThe")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .where(Field.of("title").starts_with("The "))
    .select(Field.of("title").substring(4).as_("titleWithoutLeadingThe"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .where(startsWith(field("title"), "The "))
        .select(
            substring(field("title"), constant(4), field("title").charLength())
                .as("titleWithoutLeadingThe"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Where(firestore.StartsWith(firestore.FieldOf("title"), "The ")).
	Select(firestore.Fields(
		firestore.Substring(firestore.FieldOf("title"), firestore.ConstantOf(4), firestore.FieldOf("title").CharLength()).As("titleWithoutLeadingThe"),
	)).
	Execute(ctx)

STRING_REVERSE

Sintaxis:

string_reverse[T <: STRING | BYTES](input: T) -> T

Descripción:

Devuelve la entrada proporcionada en orden inverso.

Los caracteres se delimitan por puntos de código Unicode cuando la entrada es un STRING y por bytes cuando la entrada es un valor de BYTES.

Ejemplos:

entrada string_reverse(input)
"abc" "cba"
"a🌹b" "b🌹a"
"hello" "olleh"
b"abc" b"cba"
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(
    field("name").reverse().as("reversedName")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("name").reverse().as("reversedName")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("name").reverse().as("reversedName")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("name").reverse().alias("reversedName")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("name").reverse().alias("reversedName")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("name").string_reverse().as_("reversedName"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(reverse(field("name")).as("reversedName"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.Reverse(firestore.FieldOf("name")).As("reversedName"),
	)).
	Execute(ctx)

STRING_REPEAT

Sintaxis:

string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T

Descripción:

Devuelve el valor de input repetido repetitions veces.

  • repetitions debe ser un número entero no negativo
  • Si repetitions es 0, devuelve un valor vacío del mismo tipo que input.
  • Si el resultado supera el tamaño máximo permitido (1 MB), se muestra un error.

Ejemplos:

entrada repeticiones string_repeat(input, repetitions)
"foo" 3 "foofoofoo"
"foo" 0 ""
"a " 3 "a a a "
b"ab" 2 b"abab"
"é🦆" 2 "é🦆é🦆"

STRING_REPLACE_ALL

Sintaxis:

string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T

Descripción:

Reemplaza todas las instancias no superpuestas de find en input por replacement.

  • Las coincidencias distinguen mayúsculas de minúsculas.
  • Si find está vacío, no se realizan reemplazos.

Ejemplos:

entrada buscar reemplazo string_replace_all(input, find, replacement)
"foobarfoo" "foo" "baz" "bazbarbaz"
"ababab" "aba" "c" "cbab"
"foobar" "o" "" "fbar"
"é🦆🌎🦆" "🦆" "a" "éa🌎a"
b"abc" b"b" b"d" b"adc"

STRING_REPLACE_ONE

Sintaxis:

string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T

Descripción:

Reemplaza el primer caso de find en input por replacement.

  • Las coincidencias distinguen mayúsculas de minúsculas.
  • Si find está vacío, no se realizan reemplazos.

Ejemplos:

entrada buscar reemplazo string_replace_one(input, find, replacement)
"foobarfoo" "foo" "baz" "bazbarfoo"
"é" "é" "a" "a"
b"foobar" b"o" b"z" b"fzoobar"

TRIM

Sintaxis:

trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T

Descripción:

Corta un conjunto especificado de BYTES o CHARS del principio y el final de la input proporcionada.

  • Si no se proporciona ningún values_to_trim, se quitan los caracteres de espacio en blanco.

Ejemplos:

Cuando no se proporciona values_to_trim:

entrada trim(input)
" foo " "foo"
b" foo " b"foo"
"foo" "foo"
"" ""
" " ""
"\t foo \n" "foo"
b"\t foo \n" b"foo"
"\r\f\v foo \r\f\v" "foo"
b"\r\f\v foo \r\f\v" b"foo"

Cuando se proporciona values_to_trim, ocurre lo siguiente:

entrada values_to_trim trim(input, values_to_trim)
"abcbfooaacb" "abc" "foo"
"abcdaabadbac" "abc" "daabad"
b"C1C2C3" b"C1" b"C2C3"
b"C1C2" "foo" error
"foo" b"C1" error

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("name").trim().as("whitespaceTrimmedName")
  )
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("name").trim(" \n\t").as("whitespaceTrimmedName")
  ])
  .execute()
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(
        field("name").trim().alias("whitespaceTrimmedName")
    )
    .execute()
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("name").trim().alias("whitespaceTrimmedName")
    )
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("name").trim().as_("whitespaceTrimmedName"))
    .execute()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(trim(field("name")).as("whitespaceTrimmedName"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.Trim(firestore.FieldOf("name")).As("whitespaceTrimmedName"),
	)).
	Execute(ctx)

LTRIM

Sintaxis:

ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T

Descripción:

Corta un conjunto especificado de BYTES o CHARS del principio de la value proporcionada.

  • Si no se proporciona to_trim, se quitan los caracteres de espacio en blanco iniciales.

Ejemplos:

Cuando no se proporciona to_trim:

valor ltrim(value)
" foo " "foo "
"foo" "foo"

Cuando se proporciona to_trim, ocurre lo siguiente:

valor to_trim ltrim(value, to_trim)
"aaabc" "a" "bc"
"abacaba" “ba” "caba"
"é" "é" ""

RTRIM

Sintaxis:

rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T

Descripción:

Corta un conjunto especificado de BYTES o CHARS del final del value proporcionado.

  • Si no se proporciona to_trim, se quitan los caracteres de espacio en blanco finales.

Ejemplos:

Cuando no se proporciona to_trim:

valor rtrim(value)
" foo " " foo"
"foo" "foo"

Cuando se proporciona to_trim, ocurre lo siguiente:

valor to_trim rtrim(value, to_trim)
"abccc" "c" "ab"
"abacaba" “ba” "abac"
"é" "é" ""

SPLIT

Sintaxis:

split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>

Descripción:

Divide un valor STRING o BYTES con un delimitador.

  • Para STRING, el delimitador predeterminado es la coma ,. El delimitador se trata como una sola cadena.

  • Para BYTES, debes especificar un delimitador.

  • La división en un delimitador vacío produce un array de puntos de código Unicode para los valores de STRING y un array de BYTES para los valores de BYTES.

  • Dividir una STRING vacía devuelve un ARRAY con una única STRING vacía.

Ejemplos:

Cuando no se proporciona delimiter:

entrada split(input)
"foo,bar,foo" ["foo", "bar", "foo"]
"foo" ["foo"]
",foo," ["", "foo", ""]
"" [""]
b"C120C2C4" error

Cuando se proporciona delimiter, ocurre lo siguiente:

entrada delimitador split(input, delimiter)
"foo bar foo" " " ["foo", "bar", "foo"]
"foo bar foo" "z" ["foo bar foo"]
"abc" "" ["a", "b", "c"]
b"C1,C2,C4" b"," [b"C1", b"C2", b"C4"]
b"ABC" b"" [b"A", b"B", b"C"]
"foo" b"C1" error

¿Qué sigue?