From 3f33076d2ddf6fff8540eff677269bf9db52428c Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 6 Nov 2025 14:29:25 -0800 Subject: [PATCH 1/2] remove stable snippet --- .../firestore-smoketest/PipelineSnippets.swift | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/firestore/swift/firestore-smoketest/PipelineSnippets.swift b/firestore/swift/firestore-smoketest/PipelineSnippets.swift index 9de5764..73d3130 100644 --- a/firestore/swift/firestore-smoketest/PipelineSnippets.swift +++ b/firestore/swift/firestore-smoketest/PipelineSnippets.swift @@ -411,22 +411,6 @@ public class PipelineSnippets { print(results) } - // https://cloud.google.com/firestore/docs/pipeline/stages/transformation/union#examples - func unionStageStable() async throws { - // [START union_stage_stable] - let results = try await db.pipeline() - .collection("cities/SF/restaurants") - .where(Field("type").equal("Chinese")) - .union(with: db.pipeline() - .collection("cities/NY/restaurants") - .where(Field("type").equal("Italian"))) - .where(Field("rating").greaterThanOrEqual(4.5)) - .sort([Field("__name__").descending()]) - .execute() - // [END union_stage_stable] - print(results) - } - // https://cloud.google.com/firestore/docs/pipeline/stages/transformation/unnest#examples func unnestStage() async throws { // [START unnest_stage] From cbf100a5bfdfb2717ad92bd81e55eb99ac839b99 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 6 Nov 2025 19:30:23 -0800 Subject: [PATCH 2/2] snippet updates --- .../PipelineSnippets.swift | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/firestore/swift/firestore-smoketest/PipelineSnippets.swift b/firestore/swift/firestore-smoketest/PipelineSnippets.swift index 73d3130..0c4aa48 100644 --- a/firestore/swift/firestore-smoketest/PipelineSnippets.swift +++ b/firestore/swift/firestore-smoketest/PipelineSnippets.swift @@ -27,7 +27,22 @@ public class PipelineSnippets { pipelineConcepts() } - func basicRead() async throws { + func stagesExpressionsExample() async throws { + // [START stages_expressions_example] + guard let cutoffDate = Calendar.current.date(byAdding: .month, value: -1, to: Date()) else { + return + } + let snapshot = try await db.pipeline() + .collection("productViews") + .where(Field("viewedAt").greaterThan(cutoffDate.timeIntervalSince1970)) + .aggregate([Field("productId").countDistinct().as("uniqueProductViews")]) + .execute() + // [END stages_expressions_example] + print(snapshot) + } + + func basicRead() async { + // [START basic_read] do { // Initialize a Firestore Pipeline instance and specify the "users" collection as the // input stage. @@ -43,6 +58,7 @@ public class PipelineSnippets { } catch { print("Error getting documents with pipeline: \(error)") } + // [END basic_read] } // https://cloud.google.com/firestore/docs/pipeline/overview#concepts @@ -1149,6 +1165,7 @@ public class PipelineSnippets { ]) .execute() // [END to_lower] + print(result) } // https://cloud.google.com/firestore/docs/pipeline/functions/string_functions#substr @@ -1185,7 +1202,7 @@ public class PipelineSnippets { let result = try await db.pipeline() .collection("books") .select([ - Field("name").trim().as("whitespaceTrimmedName") + Field("name").trim(" \n\t").as("whitespaceTrimmedName") ]) .execute() // [END trim_function]