Skip to content
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b17f8f1
add initial pipelines snippet file
morganchen12 Nov 3, 2025
71c481f
add pipeline snippets for python
morganchen12 Nov 4, 2025
cf8b63e
address feedback except formatting
morganchen12 Nov 6, 2025
45302f8
run format
morganchen12 Nov 6, 2025
9df189b
remove confusing async bit
morganchen12 Nov 7, 2025
f84c39d
Add expression and input snippets, with errors
morganchen12 Nov 11, 2025
b17342b
add query explain snippet and fix lint errors
morganchen12 Nov 11, 2025
79e3d2b
fix explainoptions snippet
morganchen12 Nov 12, 2025
addbcbf
add type and constant functions
morganchen12 Jan 14, 2026
84d9c85
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Apr 15, 2026
bff59b7
add snippets except forceindex (not supported)
morganchen12 Apr 15, 2026
c2db983
Add snippets for inserting data used by other snippets
morganchen12 Apr 17, 2026
eb62188
add search and geo snippets
morganchen12 Apr 20, 2026
3ab8ef2
code review feedback
morganchen12 May 15, 2026
7851ad5
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Jun 26, 2026
8ca4f37
feat(fcm): Enable `fid` and deprecate `token` for Send API (#951)
yvonnep165 Jun 29, 2026
a3f6df8
fix(deps): Added universe_domain override to MockGoogleComputeEngineC…
lahirumaramba Jun 29, 2026
ef49e31
chore(deps): update pyjwt requirement from >=2.10.1 to >=2.12.1 (#948)
dependabot[bot] Jun 29, 2026
f3e8ed8
chore(deps): update google-cloud-firestore requirement (#947)
dependabot[bot] Jun 29, 2026
486597b
chore(deps): update pytest requirement from >=8.2.2 to >=8.4.2 (#946)
dependabot[bot] Jun 29, 2026
43e5543
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Jun 29, 2026
4a6ce82
Merge branch 'main' into mc/pipelines-snippets
morganchen12 Jul 31, 2026
c4ba7c0
add snippets for joins and explain (#973)
morganchen12 Jul 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add snippets for inserting data used by other snippets
  • Loading branch information
morganchen12 committed Apr 17, 2026
commit c2db983da140d0e0a7f371d4752618e51107377b
123 changes: 123 additions & 0 deletions snippets/firestore/firestore_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import firebase_admin
from firebase_admin import firestore

Expand Down Expand Up @@ -2868,6 +2869,15 @@ def distinct_expressions_example():
print(city)



def search_basic_query_data():
# [START search_basic_query_data]
client.collection("Restaurants").add(
{"name": "Waffle Place", "description": "A cozy place for fresh waffles."}
)
# [END search_basic_query_data]


def search_basic():
# [START search_basic]
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches
Expand All @@ -2883,6 +2893,14 @@ def search_basic():
print(result)


def search_exact_match_data():
# [START search_exact_match_data]
client.collection("Restaurants").add(
{"name": "Waffle Place", "description": "A cozy place for fresh waffles."}
)
# [END search_exact_match_data]


def search_exact():
# [START search_exact]
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches
Expand All @@ -2898,6 +2916,17 @@ def search_exact():
print(result)


def search_two_terms_data():
# [START search_two_terms_data]
client.collection("Restaurants").add(
{
"name": "Morning Diner",
"description": "Start your day with waffles and eggs.",
}
)
# [END search_two_terms_data]


def search_two_terms():
# [START search_two_terms]
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches
Expand All @@ -2913,6 +2942,14 @@ def search_two_terms():
print(result)


def search_exclude_term_data():
# [START search_exclude_term_data]
client.collection("Restaurants").add(
{"name": "City Coffee", "description": "Premium coffee and pastries."}
)
# [END search_exclude_term_data]


def search_exclude():
# [START search_exclude]
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches
Expand All @@ -2928,6 +2965,14 @@ def search_exclude():
print(result)


def search_score_data():
# [START search_score_data]
client.collection("Restaurants").add(
{"name": "The Waffle Hub", "description": "Everything waffles!"}
)
# [END search_score_data]


def search_score():
# [START search_score]
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches, Score
Expand All @@ -2949,6 +2994,14 @@ def search_score():
print(result)


def define_stage_data():
# [START define_stage_data]
client.collection("Authors").document("author_123").set(
{"id": "author_123", "name": "Jane Austen"}
)
# [END define_stage_data]


def define_example():
# [START define_example]
from google.cloud.firestore_v1.pipeline_expressions import Field, Variable
Expand All @@ -2972,6 +3025,20 @@ def define_example():
print(r)


def to_array_expression_stage_data():
# [START to_array_expression_stage_data]
client.collection("Projects").document("project_1").set(
{"id": "project_1", "name": "Alpha Build"}
)
tasks = [
{"project_id": "project_1", "title": "System Architecture"},
{"project_id": "project_1", "title": "Database Schema Design"},
]
for task in tasks:
client.collection("Tasks").add(task)
# [END to_array_expression_stage_data]


def to_array_example():
# [START to_array_example]
from google.cloud.firestore_v1.pipeline_expressions import Field, Variable
Expand All @@ -2995,6 +3062,20 @@ def to_array_example():
print(result)


def to_scalar_expression_stage_data():
# [START to_scalar_expression_stage_data]
client.collection("Authors").document("author_202").set(
{"id": "author_202", "name": "Charles Dickens"}
)
books = [
{"author_id": "author_202", "title": "Great Expectations", "rating": 4.8},
{"author_id": "author_202", "title": "Oliver Twist", "rating": 4.5},
]
for book in books:
client.collection("Books").add(book)
# [END to_scalar_expression_stage_data]


def to_scalar_example():
# [START to_scalar_example]
from google.cloud.firestore_v1.pipeline_expressions import Field, Variable
Expand All @@ -3018,6 +3099,32 @@ def to_scalar_example():
print(result)


def force_index_example():
# [START force_index_example]
# Note: forceIndex is not currently supported in the Python SDK.
results = client.pipeline().collection_group("customers").limit(100).execute()
# [END force_index_example]
for result in results:
print(result)


def force_scan_example():
# [START force_scan_example]
# Note: forceIndex="primary" is not currently supported in the Python SDK.
results = client.pipeline().collection_group("customers").limit(100).execute()
# [END force_scan_example]
for result in results:
print(result)


def update_dml_example_data():
# [START update_dml_example_data]
client.collection("Users").document("userID").set(
{"id": "userID", "preferences": {}, "color": "#FFFFFF"}
)
# [END update_dml_example_data]


def pipeline_update_example():
# [START pipeline_update]
from google.cloud.firestore_v1.pipeline_expressions import Constant, Field, Not
Expand All @@ -3035,6 +3142,22 @@ def pipeline_update_example():
print(snapshot)


def delete_dml_example_data():
# [START delete_dml_example_data]
import datetime

client.collection("Users").document("userID").set(
{
"id": "userID",
"address": {"country": "USA", "state": "CA"},
"__create_time__": datetime.datetime.fromtimestamp(
946684800000 / 1000, tz=datetime.timezone.utc
),
}
)
# [END delete_dml_example_data]


def pipeline_delete_example():
# [START pipeline_delete]
from google.cloud.firestore_v1.pipeline_expressions import CurrentTimestamp, Field
Expand Down
Loading