mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
Fix syntax in Pipeline examples in TSDoc (#9712)
This commit is contained in:
@@ -127,7 +127,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error
|
||||
// but always returns a boolean expression.
|
||||
constant(50).divide('length').gt(1).ifError(constant(false));
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(constant(false));
|
||||
|
||||
```
|
||||
|
||||
@@ -162,7 +162,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error
|
||||
// but always returns a boolean expression.
|
||||
constant(50).divide('length').gt(1).ifError(false);
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(false);
|
||||
|
||||
```
|
||||
|
||||
@@ -196,7 +196,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error.
|
||||
constant(50).divide('length').gt(1).ifError(constant(0));
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(constant(0));
|
||||
|
||||
```
|
||||
|
||||
@@ -230,7 +230,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error.
|
||||
constant(50).divide('length').gt(1).ifError(0);
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(0);
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -1389,7 +1389,7 @@ A new `Ordering` for ascending sorting.
|
||||
|
||||
```typescript
|
||||
// Sort documents by the 'name' field in ascending order
|
||||
pipeline().collection("users")
|
||||
firestore.pipeline().collection("users")
|
||||
.sort(field("name").ascending());
|
||||
|
||||
```
|
||||
@@ -2043,7 +2043,7 @@ A new `Expression` representing the 'IN' comparison.
|
||||
|
||||
```typescript
|
||||
// Check if the 'category' field is either "Electronics" or value of field 'primaryType'
|
||||
field("category").equalAny("Electronics", field("primaryType"));
|
||||
field("category").equalAny(["Electronics", field("primaryType")]);
|
||||
|
||||
```
|
||||
|
||||
@@ -2557,7 +2557,6 @@ A new [BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpr
|
||||
```typescript
|
||||
// Check if the field `value` is absent.
|
||||
field("value").isAbsent();
|
||||
@example
|
||||
|
||||
```
|
||||
|
||||
@@ -3038,7 +3037,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Returns the larger value between the 'timestamp' field and the current timestamp.
|
||||
field("timestamp").logicalMaximum(Function.currentTimestamp());
|
||||
field("timestamp").logicalMaximum(currentTimestamp());
|
||||
|
||||
```
|
||||
|
||||
@@ -3073,7 +3072,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Returns the smaller value between the 'timestamp' field and the current timestamp.
|
||||
field("timestamp").logicalMinimum(Function.currentTimestamp());
|
||||
field("timestamp").logicalMinimum(currentTimestamp());
|
||||
|
||||
```
|
||||
|
||||
@@ -4239,7 +4238,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -2024,7 +2024,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create an array value from the input array and reference the 'baz' field value from the input document.
|
||||
array(['bar', Field.of('baz')]).as('foo');
|
||||
array(['bar', field('baz')]).as('foo');
|
||||
|
||||
```
|
||||
|
||||
@@ -2058,7 +2058,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create a map from the input object and reference the 'baz' field value from the input document.
|
||||
map({foo: 'bar', baz: Field.of('baz')}).as('data');
|
||||
map({foo: 'bar', baz: field('baz')}).as('data');
|
||||
|
||||
```
|
||||
|
||||
@@ -3634,7 +3634,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
split(field('scores'), conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
split(field('scores'), conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
|
||||
```
|
||||
|
||||
@@ -4086,7 +4086,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Reverse the value of the 'myString' field.
|
||||
strReverse("myString");
|
||||
stringReverse("myString");
|
||||
|
||||
```
|
||||
|
||||
@@ -5250,7 +5250,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Get the character length of the 'name' field in UTF-8.
|
||||
strLength("name");
|
||||
charLength("name");
|
||||
|
||||
```
|
||||
|
||||
@@ -7527,7 +7527,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
split('scores', conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
split('scores', conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
|
||||
```
|
||||
|
||||
@@ -9330,7 +9330,7 @@ A new `Expression` representing the greater than comparison.
|
||||
|
||||
```typescript
|
||||
// Check if the 'age' field is greater than 18
|
||||
greaterThan(field("age"), Constant(9).add(9));
|
||||
greaterThan(field("age"), constant(9).add(9));
|
||||
|
||||
```
|
||||
|
||||
@@ -10193,7 +10193,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Get the character length of the 'name' field in UTF-8.
|
||||
strLength(field("name"));
|
||||
charLength(field("name"));
|
||||
|
||||
```
|
||||
|
||||
@@ -10829,7 +10829,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Reverse the value of the 'myString' field.
|
||||
strReverse(field("myString"));
|
||||
stringReverse(field("myString"));
|
||||
|
||||
```
|
||||
|
||||
@@ -10897,7 +10897,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Convert the 'title' field to uppercase
|
||||
toUppercase(field("title"));
|
||||
toUpper(field("title"));
|
||||
|
||||
```
|
||||
|
||||
@@ -11195,7 +11195,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error
|
||||
// but always returns a boolean expression.
|
||||
ifError(constant(50).divide('length').gt(1), constant(false));
|
||||
ifError(constant(50).divide(field('length')).greaterThan(1), constant(false));
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ A new Pipeline object with this stage appended to the stage list.
|
||||
firestore.pipeline().collection("books")
|
||||
.addFields(
|
||||
field("rating").as("bookRating"), // Rename 'rating' to 'bookRating'
|
||||
add(5, field("quantity")).as("totalCost") // Calculate 'totalCost'
|
||||
add(field("quantity"), 5).as("totalCost") // Calculate 'totalCost'
|
||||
);
|
||||
|
||||
```
|
||||
@@ -165,7 +165,7 @@ A new Pipeline object with this stage appended to the stage list.
|
||||
firestore.pipeline().collection("books")
|
||||
.addFields(
|
||||
field("rating").as("bookRating"), // Rename 'rating' to 'bookRating'
|
||||
add(5, field("quantity")).as("totalCost") // Calculate 'totalCost'
|
||||
add(field("quantity"), 5).as("totalCost") // Calculate 'totalCost'
|
||||
);
|
||||
|
||||
```
|
||||
@@ -207,7 +207,7 @@ A new Pipeline object with this stage appended to the stage list.
|
||||
// Calculate the average rating and the total number of books
|
||||
firestore.pipeline().collection("books")
|
||||
.aggregate(
|
||||
field("rating").avg().as("averageRating"),
|
||||
field("rating").average().as("averageRating"),
|
||||
countAll().as("totalBooks")
|
||||
);
|
||||
|
||||
@@ -251,7 +251,7 @@ A new [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class) object with t
|
||||
// Calculate the average rating for each genre.
|
||||
firestore.pipeline().collection("books")
|
||||
.aggregate({
|
||||
accumulators: [avg(field("rating")).as("avg_rating")]
|
||||
accumulators: [average(field("rating")).as("avg_rating")],
|
||||
groups: ["genre"]
|
||||
});
|
||||
|
||||
@@ -297,7 +297,7 @@ A new [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class) object with t
|
||||
```typescript
|
||||
// Get a list of unique author names in uppercase and genre combinations.
|
||||
firestore.pipeline().collection("books")
|
||||
.distinct(toUppercase(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
.distinct(toUpper(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
.select("authorName");
|
||||
|
||||
```
|
||||
@@ -341,7 +341,7 @@ A new [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class) object with t
|
||||
```typescript
|
||||
// Get a list of unique author names in uppercase and genre combinations.
|
||||
firestore.pipeline().collection("books")
|
||||
.distinct(toUppercase(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
.distinct(toUpper(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
.select("authorName");
|
||||
|
||||
```
|
||||
@@ -594,7 +594,7 @@ A new [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class) object with t
|
||||
```typescript
|
||||
// Assume we don't have a built-in 'where' stage
|
||||
firestore.pipeline().collection('books')
|
||||
.rawStage('where', [field('published').lt(1900)]) // Custom 'where' stage
|
||||
.rawStage('where', [field('published').lessThan(1900)]) // Custom 'where' stage
|
||||
.select('title', 'author');
|
||||
|
||||
```
|
||||
@@ -971,7 +971,7 @@ db.pipeline().collection("books")
|
||||
.select(
|
||||
"firstName",
|
||||
field("lastName"),
|
||||
field("address").toUppercase().as("upperAddress"),
|
||||
field("address").toUpper().as("upperAddress"),
|
||||
);
|
||||
|
||||
```
|
||||
@@ -1017,7 +1017,7 @@ db.pipeline().collection("books")
|
||||
.select(
|
||||
"firstName",
|
||||
field("lastName"),
|
||||
field("address").toUppercase().as("upperAddress"),
|
||||
field("address").toUpper().as("upperAddress"),
|
||||
);
|
||||
|
||||
```
|
||||
@@ -1060,8 +1060,8 @@ A new [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class) object with t
|
||||
// with the same rating
|
||||
firestore.pipeline().collection("books")
|
||||
.sort(
|
||||
Ordering.of(field("rating")).descending(),
|
||||
Ordering.of(field("title")) // Ascending order is the default
|
||||
field("rating").descending(),
|
||||
field("title").ascending()
|
||||
);
|
||||
|
||||
```
|
||||
@@ -1103,8 +1103,8 @@ A new [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class) object with t
|
||||
// with the same rating
|
||||
firestore.pipeline().collection("books")
|
||||
.sort(
|
||||
Ordering.of(field("rating")).descending(),
|
||||
Ordering.of(field("title")) // Ascending order is the default
|
||||
field("rating").descending(),
|
||||
field("title").ascending()
|
||||
);
|
||||
|
||||
```
|
||||
@@ -1328,8 +1328,8 @@ A new Pipeline object with this stage appended to the stage list.
|
||||
firestore.pipeline().collection("books")
|
||||
.where(
|
||||
and(
|
||||
gt(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
field("genre").eq("Science Fiction") // Equivalent to gt("genre", "Science Fiction")
|
||||
greaterThan(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
field("genre").equal("Science Fiction") // Equivalent to equal("genre", "Science Fiction")
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1373,8 +1373,8 @@ A new Pipeline object with this stage appended to the stage list.
|
||||
firestore.pipeline().collection("books")
|
||||
.where(
|
||||
and(
|
||||
gt(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
field("genre").eq("Science Fiction") // Equivalent to gt("genre", "Science Fiction")
|
||||
greaterThan(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
field("genre").equal("Science Fiction") // Equivalent to equal("genre", "Science Fiction")
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1394,13 +1394,13 @@ const results1 = await execute(db.pipeline()
|
||||
// Example 2: Filter documents where 'genre' is "Science Fiction" and 'published' is after 1950
|
||||
const results2 = await execute(db.pipeline()
|
||||
.collection("books")
|
||||
.where(and(field("genre").eq("Science Fiction"), field("published").gt(1950))));
|
||||
.where(and(field("genre").equal("Science Fiction"), field("published").greaterThan(1950))));
|
||||
|
||||
// Example 3: Calculate the average rating of books published after 1980
|
||||
const results3 = await execute(db.pipeline()
|
||||
.collection("books")
|
||||
.where(field("published").gt(1980))
|
||||
.aggregate(avg(field("rating")).as("averageRating")));
|
||||
.where(field("published").greaterThan(1980))
|
||||
.aggregate(average(field("rating")).as("averageRating")));
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error
|
||||
// but always returns a boolean expression.
|
||||
constant(50).divide('length').gt(1).ifError(constant(false));
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(constant(false));
|
||||
|
||||
```
|
||||
|
||||
@@ -162,7 +162,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error
|
||||
// but always returns a boolean expression.
|
||||
constant(50).divide('length').gt(1).ifError(false);
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(false);
|
||||
|
||||
```
|
||||
|
||||
@@ -196,7 +196,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error.
|
||||
constant(50).divide('length').gt(1).ifError(constant(0));
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(constant(0));
|
||||
|
||||
```
|
||||
|
||||
@@ -230,7 +230,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error.
|
||||
constant(50).divide('length').gt(1).ifError(0);
|
||||
constant(50).divide(field('length')).greaterThan(1).ifError(0);
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -1389,7 +1389,7 @@ A new `Ordering` for ascending sorting.
|
||||
|
||||
```typescript
|
||||
// Sort documents by the 'name' field in ascending order
|
||||
pipeline().collection("users")
|
||||
firestore.pipeline().collection("users")
|
||||
.sort(field("name").ascending());
|
||||
|
||||
```
|
||||
@@ -2043,7 +2043,7 @@ A new `Expression` representing the 'IN' comparison.
|
||||
|
||||
```typescript
|
||||
// Check if the 'category' field is either "Electronics" or value of field 'primaryType'
|
||||
field("category").equalAny("Electronics", field("primaryType"));
|
||||
field("category").equalAny(["Electronics", field("primaryType")]);
|
||||
|
||||
```
|
||||
|
||||
@@ -2557,7 +2557,6 @@ A new [BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpr
|
||||
```typescript
|
||||
// Check if the field `value` is absent.
|
||||
field("value").isAbsent();
|
||||
@example
|
||||
|
||||
```
|
||||
|
||||
@@ -3038,7 +3037,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Returns the larger value between the 'timestamp' field and the current timestamp.
|
||||
field("timestamp").logicalMaximum(Function.currentTimestamp());
|
||||
field("timestamp").logicalMaximum(currentTimestamp());
|
||||
|
||||
```
|
||||
|
||||
@@ -3073,7 +3072,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Returns the smaller value between the 'timestamp' field and the current timestamp.
|
||||
field("timestamp").logicalMinimum(Function.currentTimestamp());
|
||||
field("timestamp").logicalMinimum(currentTimestamp());
|
||||
|
||||
```
|
||||
|
||||
@@ -4239,7 +4238,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -2030,7 +2030,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create an array value from the input array and reference the 'baz' field value from the input document.
|
||||
array(['bar', Field.of('baz')]).as('foo');
|
||||
array(['bar', field('baz')]).as('foo');
|
||||
|
||||
```
|
||||
|
||||
@@ -2064,7 +2064,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Create a map from the input object and reference the 'baz' field value from the input document.
|
||||
map({foo: 'bar', baz: Field.of('baz')}).as('data');
|
||||
map({foo: 'bar', baz: field('baz')}).as('data');
|
||||
|
||||
```
|
||||
|
||||
@@ -3640,7 +3640,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
split(field('scores'), conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
split(field('scores'), conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
|
||||
```
|
||||
|
||||
@@ -4092,7 +4092,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Reverse the value of the 'myString' field.
|
||||
strReverse("myString");
|
||||
stringReverse("myString");
|
||||
|
||||
```
|
||||
|
||||
@@ -5256,7 +5256,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Get the character length of the 'name' field in UTF-8.
|
||||
strLength("name");
|
||||
charLength("name");
|
||||
|
||||
```
|
||||
|
||||
@@ -7533,7 +7533,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
split('scores', conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
split('scores', conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
|
||||
```
|
||||
|
||||
@@ -9336,7 +9336,7 @@ A new `Expression` representing the greater than comparison.
|
||||
|
||||
```typescript
|
||||
// Check if the 'age' field is greater than 18
|
||||
greaterThan(field("age"), Constant(9).add(9));
|
||||
greaterThan(field("age"), constant(9).add(9));
|
||||
|
||||
```
|
||||
|
||||
@@ -10157,10 +10157,10 @@ A Promise representing the asynchronous pipeline execution.
|
||||
|
||||
```typescript
|
||||
const snapshot: PipelineSnapshot = await execute(firestore.pipeline().collection("books")
|
||||
.where(gt(field("rating"), 4.5))
|
||||
.where(greaterThan(field("rating"), 4.5))
|
||||
.select("title", "author", "rating"));
|
||||
|
||||
const results: PipelineResults = snapshot.results;
|
||||
const results: PipelineResult[] = snapshot.results;
|
||||
|
||||
```
|
||||
|
||||
@@ -10229,10 +10229,10 @@ A Promise representing the asynchronous pipeline execution.
|
||||
|
||||
```typescript
|
||||
const snapshot: PipelineSnapshot = await execute(firestore.pipeline().collection("books")
|
||||
.where(gt(field("rating"), 4.5))
|
||||
.where(greaterThan(field("rating"), 4.5))
|
||||
.select("title", "author", "rating"));
|
||||
|
||||
const results: PipelineResults = snapshot.results;
|
||||
const results: PipelineResult[] = snapshot.results;
|
||||
|
||||
```
|
||||
|
||||
@@ -10268,7 +10268,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Get the character length of the 'name' field in UTF-8.
|
||||
strLength(field("name"));
|
||||
charLength(field("name"));
|
||||
|
||||
```
|
||||
|
||||
@@ -10904,7 +10904,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Reverse the value of the 'myString' field.
|
||||
strReverse(field("myString"));
|
||||
stringReverse(field("myString"));
|
||||
|
||||
```
|
||||
|
||||
@@ -10972,7 +10972,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
|
||||
```typescript
|
||||
// Convert the 'title' field to uppercase
|
||||
toUppercase(field("title"));
|
||||
toUpper(field("title"));
|
||||
|
||||
```
|
||||
|
||||
@@ -11270,7 +11270,7 @@ A new [Expression](./firestore_pipelines.expression.md#expression_class) represe
|
||||
```typescript
|
||||
// Create an expression that protects against a divide by zero error
|
||||
// but always returns a boolean expression.
|
||||
ifError(constant(50).divide('length').gt(1), constant(false));
|
||||
ifError(constant(50).divide(field('length')).greaterThan(1), constant(false));
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -77,10 +77,10 @@ declare module './database' {
|
||||
* @example
|
||||
* ```typescript
|
||||
* const snapshot: PipelineSnapshot = await execute(firestore.pipeline().collection("books")
|
||||
* .where(gt(field("rating"), 4.5))
|
||||
* .where(greaterThan(field("rating"), 4.5))
|
||||
* .select("title", "author", "rating"));
|
||||
*
|
||||
* const results: PipelineResults = snapshot.results;
|
||||
* const results: PipelineResult[] = snapshot.results;
|
||||
* ```
|
||||
*
|
||||
* @param pipeline - The pipeline to execute.
|
||||
@@ -112,10 +112,10 @@ export function execute(pipeline: LitePipeline): Promise<PipelineSnapshot>;
|
||||
* @example
|
||||
* ```typescript
|
||||
* const snapshot: PipelineSnapshot = await execute(firestore.pipeline().collection("books")
|
||||
* .where(gt(field("rating"), 4.5))
|
||||
* .where(greaterThan(field("rating"), 4.5))
|
||||
* .select("title", "author", "rating"));
|
||||
*
|
||||
* const results: PipelineResults = snapshot.results;
|
||||
* const results: PipelineResult[] = snapshot.results;
|
||||
* ```
|
||||
*
|
||||
* @param options - Specifies the pipeline to execute and other options for execute.
|
||||
|
||||
@@ -772,7 +772,7 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Check if the 'category' field is either "Electronics" or value of field 'primaryType'
|
||||
* field("category").equalAny("Electronics", field("primaryType"));
|
||||
* field("category").equalAny(["Electronics", field("primaryType")]);
|
||||
* ```
|
||||
*
|
||||
* @param values - The values or expressions to check against.
|
||||
@@ -2218,7 +2218,7 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Returns the larger value between the 'timestamp' field and the current timestamp.
|
||||
* field("timestamp").logicalMaximum(Function.currentTimestamp());
|
||||
* field("timestamp").logicalMaximum(currentTimestamp());
|
||||
* ```
|
||||
*
|
||||
* @param second - The second expression or literal to compare with.
|
||||
@@ -2244,7 +2244,7 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Returns the smaller value between the 'timestamp' field and the current timestamp.
|
||||
* field("timestamp").logicalMinimum(Function.currentTimestamp());
|
||||
* field("timestamp").logicalMinimum(currentTimestamp());
|
||||
* ```
|
||||
*
|
||||
* @param second - The second expression or literal to compare with.
|
||||
@@ -2796,7 +2796,6 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
|
||||
* ```typescript
|
||||
* // Check if the field `value` is absent.
|
||||
* field("value").isAbsent();
|
||||
* @example
|
||||
* ```
|
||||
*
|
||||
* @returns A new {@link @firebase/firestore/pipelines#BooleanExpression} representing the 'isAbsent' check.
|
||||
@@ -3237,7 +3236,7 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
* field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
* field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
* ```
|
||||
*
|
||||
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the split function.
|
||||
@@ -3311,7 +3310,7 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Sort documents by the 'name' field in ascending order
|
||||
* pipeline().collection("users")
|
||||
* firestore.pipeline().collection("users")
|
||||
* .sort(field("name").ascending());
|
||||
* ```
|
||||
*
|
||||
@@ -4029,7 +4028,7 @@ export abstract class BooleanExpression extends Expression {
|
||||
* ```typescript
|
||||
* // Create an expression that protects against a divide by zero error
|
||||
* // but always returns a boolean expression.
|
||||
* constant(50).divide('length').gt(1).ifError(constant(false));
|
||||
* constant(50).divide(field('length')).greaterThan(1).ifError(constant(false));
|
||||
* ```
|
||||
*
|
||||
* @param catchValue - The value that will be returned if this expression
|
||||
@@ -4048,7 +4047,7 @@ export abstract class BooleanExpression extends Expression {
|
||||
* ```typescript
|
||||
* // Create an expression that protects against a divide by zero error
|
||||
* // but always returns a boolean expression.
|
||||
* constant(50).divide('length').gt(1).ifError(false);
|
||||
* constant(50).divide(field('length')).greaterThan(1).ifError(false);
|
||||
* ```
|
||||
*
|
||||
* @param catchValue - The value that will be returned if this expression
|
||||
@@ -4066,7 +4065,7 @@ export abstract class BooleanExpression extends Expression {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Create an expression that protects against a divide by zero error.
|
||||
* constant(50).divide('length').gt(1).ifError(constant(0));
|
||||
* constant(50).divide(field('length')).greaterThan(1).ifError(constant(0));
|
||||
* ```
|
||||
*
|
||||
* @param catchValue - The value that will be returned if this expression
|
||||
@@ -4084,7 +4083,7 @@ export abstract class BooleanExpression extends Expression {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Create an expression that protects against a divide by zero error.
|
||||
* constant(50).divide('length').gt(1).ifError(0);
|
||||
* constant(50).divide(field('length')).greaterThan(1).ifError(0);
|
||||
* ```
|
||||
*
|
||||
* @param catchValue - The value that will be returned if this expression
|
||||
@@ -4283,7 +4282,7 @@ export function isError(value: Expression): BooleanExpression {
|
||||
* ```typescript
|
||||
* // Create an expression that protects against a divide by zero error
|
||||
* // but always returns a boolean expression.
|
||||
* ifError(constant(50).divide('length').gt(1), constant(false));
|
||||
* ifError(constant(50).divide(field('length')).greaterThan(1), constant(false));
|
||||
* ```
|
||||
*
|
||||
* @param tryExpr - The try expression.
|
||||
@@ -4991,7 +4990,7 @@ export function mod(
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Create a map from the input object and reference the 'baz' field value from the input document.
|
||||
* map({foo: 'bar', baz: Field.of('baz')}).as('data');
|
||||
* map({foo: 'bar', baz: field('baz')}).as('data');
|
||||
* ```
|
||||
*
|
||||
* @param elements - The input map to evaluate in the expression.
|
||||
@@ -5045,7 +5044,7 @@ export function _mapValue(plainObject: Record<string, unknown>): MapValue {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Create an array value from the input array and reference the 'baz' field value from the input document.
|
||||
* array(['bar', Field.of('baz')]).as('foo');
|
||||
* array(['bar', field('baz')]).as('foo');
|
||||
* ```
|
||||
*
|
||||
* @param elements - The input array to evaluate in the expression.
|
||||
@@ -5414,7 +5413,7 @@ export function lessThanOrEqual(
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Check if the 'age' field is greater than 18
|
||||
* greaterThan(field("age"), Constant(9).add(9));
|
||||
* greaterThan(field("age"), constant(9).add(9));
|
||||
* ```
|
||||
*
|
||||
* @param left - The first expression to compare.
|
||||
@@ -6572,7 +6571,7 @@ export function countDistinct(expr: Expression | string): AggregateFunction {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Get the character length of the 'name' field in UTF-8.
|
||||
* strLength("name");
|
||||
* charLength("name");
|
||||
* ```
|
||||
*
|
||||
* @param fieldName - The name of the field containing the string.
|
||||
@@ -6588,7 +6587,7 @@ export function charLength(fieldName: string): FunctionExpression;
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Get the character length of the 'name' field in UTF-8.
|
||||
* strLength(field("name"));
|
||||
* charLength(field("name"));
|
||||
* ```
|
||||
*
|
||||
* @param stringExpression - The expression representing the string to calculate the length of.
|
||||
@@ -8028,7 +8027,7 @@ export function toUpper(fieldName: string): FunctionExpression;
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Convert the 'title' field to uppercase
|
||||
* toUppercase(field("title"));
|
||||
* toUpper(field("title"));
|
||||
* ```
|
||||
*
|
||||
* @param stringExpression - The expression representing the string to convert to uppercase.
|
||||
@@ -10340,7 +10339,7 @@ export function sqrt(expr: Expression | string): FunctionExpression {
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Reverse the value of the 'myString' field.
|
||||
* strReverse(field("myString"));
|
||||
* stringReverse(field("myString"));
|
||||
* ```
|
||||
*
|
||||
* @param stringExpression - An expression evaluating to a string value, which will be reversed.
|
||||
@@ -10355,7 +10354,7 @@ export function stringReverse(stringExpression: Expression): FunctionExpression;
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Reverse the value of the 'myString' field.
|
||||
* strReverse("myString");
|
||||
* stringReverse("myString");
|
||||
* ```
|
||||
*
|
||||
* @param field - The name of the field representing the string to reverse.
|
||||
@@ -10696,7 +10695,7 @@ export function split(fieldName: string, delimiter: string): FunctionExpression;
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
* split('scores', conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
* split('scores', conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
* ```
|
||||
*
|
||||
* @param fieldName - Split the value in this field.
|
||||
@@ -10736,7 +10735,7 @@ export function split(
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Split the 'scores' field on delimiter ',' or ':' depending on the stored format
|
||||
* split(field('scores'), conditional(field('format').equal('csv'), constant(','), constant(':'))
|
||||
* split(field('scores'), conditional(field('format').equal('csv'), constant(','), constant(':')))
|
||||
* ```
|
||||
*
|
||||
* @param expression - Split the result of this expression.
|
||||
|
||||
@@ -119,13 +119,13 @@ import { AbstractUserDataWriter } from './user_data_writer';
|
||||
* // Example 2: Filter documents where 'genre' is "Science Fiction" and 'published' is after 1950
|
||||
* const results2 = await execute(db.pipeline()
|
||||
* .collection("books")
|
||||
* .where(and(field("genre").eq("Science Fiction"), field("published").gt(1950))));
|
||||
* .where(and(field("genre").equal("Science Fiction"), field("published").greaterThan(1950))));
|
||||
*
|
||||
* // Example 3: Calculate the average rating of books published after 1980
|
||||
* const results3 = await execute(db.pipeline()
|
||||
* .collection("books")
|
||||
* .where(field("published").gt(1980))
|
||||
* .aggregate(avg(field("rating")).as("averageRating")));
|
||||
* .where(field("published").greaterThan(1980))
|
||||
* .aggregate(average(field("rating")).as("averageRating")));
|
||||
* ```
|
||||
*/
|
||||
export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
@@ -181,7 +181,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* firestore.pipeline().collection("books")
|
||||
* .addFields(
|
||||
* field("rating").as("bookRating"), // Rename 'rating' to 'bookRating'
|
||||
* add(5, field("quantity")).as("totalCost") // Calculate 'totalCost'
|
||||
* add(field("quantity"), 5).as("totalCost") // Calculate 'totalCost'
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
@@ -211,7 +211,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* firestore.pipeline().collection("books")
|
||||
* .addFields(
|
||||
* field("rating").as("bookRating"), // Rename 'rating' to 'bookRating'
|
||||
* add(5, field("quantity")).as("totalCost") // Calculate 'totalCost'
|
||||
* add(field("quantity"), 5).as("totalCost") // Calculate 'totalCost'
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
@@ -352,7 +352,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* .select(
|
||||
* "firstName",
|
||||
* field("lastName"),
|
||||
* field("address").toUppercase().as("upperAddress"),
|
||||
* field("address").toUpper().as("upperAddress"),
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
@@ -391,7 +391,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* .select(
|
||||
* "firstName",
|
||||
* field("lastName"),
|
||||
* field("address").toUppercase().as("upperAddress"),
|
||||
* field("address").toUpper().as("upperAddress"),
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
@@ -457,8 +457,8 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* firestore.pipeline().collection("books")
|
||||
* .where(
|
||||
* and(
|
||||
* gt(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
* field("genre").eq("Science Fiction") // Equivalent to gt("genre", "Science Fiction")
|
||||
* greaterThan(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
* field("genre").equal("Science Fiction") // Equivalent to equal("genre", "Science Fiction")
|
||||
* )
|
||||
* );
|
||||
* ```
|
||||
@@ -491,8 +491,8 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* firestore.pipeline().collection("books")
|
||||
* .where(
|
||||
* and(
|
||||
* gt(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
* field("genre").eq("Science Fiction") // Equivalent to gt("genre", "Science Fiction")
|
||||
* greaterThan(field("rating"), 4.0), // Filter for ratings greater than 4.0
|
||||
* field("genre").equal("Science Fiction") // Equivalent to equal("genre", "Science Fiction")
|
||||
* )
|
||||
* );
|
||||
* ```
|
||||
@@ -694,7 +694,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* ```typescript
|
||||
* // Get a list of unique author names in uppercase and genre combinations.
|
||||
* firestore.pipeline().collection("books")
|
||||
* .distinct(toUppercase(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
* .distinct(toUpper(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
* .select("authorName");
|
||||
* ```
|
||||
*
|
||||
@@ -728,7 +728,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* ```typescript
|
||||
* // Get a list of unique author names in uppercase and genre combinations.
|
||||
* firestore.pipeline().collection("books")
|
||||
* .distinct(toUppercase(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
* .distinct(toUpper(field("author")).as("authorName"), field("genre"), "publishedAt")
|
||||
* .select("authorName");
|
||||
* ```
|
||||
*
|
||||
@@ -783,7 +783,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* // Calculate the average rating and the total number of books
|
||||
* firestore.pipeline().collection("books")
|
||||
* .aggregate(
|
||||
* field("rating").avg().as("averageRating"),
|
||||
* field("rating").average().as("averageRating"),
|
||||
* countAll().as("totalBooks")
|
||||
* );
|
||||
* ```
|
||||
@@ -823,7 +823,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* // Calculate the average rating for each genre.
|
||||
* firestore.pipeline().collection("books")
|
||||
* .aggregate({
|
||||
* accumulators: [avg(field("rating")).as("avg_rating")]
|
||||
* accumulators: [average(field("rating")).as("avg_rating")],
|
||||
* groups: ["genre"]
|
||||
* });
|
||||
* ```
|
||||
@@ -949,8 +949,8 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* // with the same rating
|
||||
* firestore.pipeline().collection("books")
|
||||
* .sort(
|
||||
* Ordering.of(field("rating")).descending(),
|
||||
* Ordering.of(field("title")) // Ascending order is the default
|
||||
* field("rating").descending(),
|
||||
* field("title").ascending()
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
@@ -977,8 +977,8 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* // with the same rating
|
||||
* firestore.pipeline().collection("books")
|
||||
* .sort(
|
||||
* Ordering.of(field("rating")).descending(),
|
||||
* Ordering.of(field("title")) // Ascending order is the default
|
||||
* field("rating").descending(),
|
||||
* field("title").ascending()
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
@@ -1419,7 +1419,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
|
||||
* ```typescript
|
||||
* // Assume we don't have a built-in 'where' stage
|
||||
* firestore.pipeline().collection('books')
|
||||
* .rawStage('where', [field('published').lt(1900)]) // Custom 'where' stage
|
||||
* .rawStage('where', [field('published').lessThan(1900)]) // Custom 'where' stage
|
||||
* .select('title', 'author');
|
||||
* ```
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user