1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import datetime
1516import firebase_admin
1617from firebase_admin import firestore
1718
@@ -2868,6 +2869,15 @@ def distinct_expressions_example():
28682869 print (city )
28692870
28702871
2872+
2873+ def search_basic_query_data ():
2874+ # [START search_basic_query_data]
2875+ client .collection ("Restaurants" ).add (
2876+ {"name" : "Waffle Place" , "description" : "A cozy place for fresh waffles." }
2877+ )
2878+ # [END search_basic_query_data]
2879+
2880+
28712881def search_basic ():
28722882 # [START search_basic]
28732883 from google .cloud .firestore_v1 .pipeline_expressions import DocumentMatches
@@ -2883,6 +2893,14 @@ def search_basic():
28832893 print (result )
28842894
28852895
2896+ def search_exact_match_data ():
2897+ # [START search_exact_match_data]
2898+ client .collection ("Restaurants" ).add (
2899+ {"name" : "Waffle Place" , "description" : "A cozy place for fresh waffles." }
2900+ )
2901+ # [END search_exact_match_data]
2902+
2903+
28862904def search_exact ():
28872905 # [START search_exact]
28882906 from google .cloud .firestore_v1 .pipeline_expressions import DocumentMatches
@@ -2898,6 +2916,17 @@ def search_exact():
28982916 print (result )
28992917
29002918
2919+ def search_two_terms_data ():
2920+ # [START search_two_terms_data]
2921+ client .collection ("Restaurants" ).add (
2922+ {
2923+ "name" : "Morning Diner" ,
2924+ "description" : "Start your day with waffles and eggs." ,
2925+ }
2926+ )
2927+ # [END search_two_terms_data]
2928+
2929+
29012930def search_two_terms ():
29022931 # [START search_two_terms]
29032932 from google .cloud .firestore_v1 .pipeline_expressions import DocumentMatches
@@ -2913,6 +2942,14 @@ def search_two_terms():
29132942 print (result )
29142943
29152944
2945+ def search_exclude_term_data ():
2946+ # [START search_exclude_term_data]
2947+ client .collection ("Restaurants" ).add (
2948+ {"name" : "City Coffee" , "description" : "Premium coffee and pastries." }
2949+ )
2950+ # [END search_exclude_term_data]
2951+
2952+
29162953def search_exclude ():
29172954 # [START search_exclude]
29182955 from google .cloud .firestore_v1 .pipeline_expressions import DocumentMatches
@@ -2928,6 +2965,14 @@ def search_exclude():
29282965 print (result )
29292966
29302967
2968+ def search_score_data ():
2969+ # [START search_score_data]
2970+ client .collection ("Restaurants" ).add (
2971+ {"name" : "The Waffle Hub" , "description" : "Everything waffles!" }
2972+ )
2973+ # [END search_score_data]
2974+
2975+
29312976def search_score ():
29322977 # [START search_score]
29332978 from google .cloud .firestore_v1 .pipeline_expressions import DocumentMatches , Score
@@ -2949,6 +2994,14 @@ def search_score():
29492994 print (result )
29502995
29512996
2997+ def define_stage_data ():
2998+ # [START define_stage_data]
2999+ client .collection ("Authors" ).document ("author_123" ).set (
3000+ {"id" : "author_123" , "name" : "Jane Austen" }
3001+ )
3002+ # [END define_stage_data]
3003+
3004+
29523005def define_example ():
29533006 # [START define_example]
29543007 from google .cloud .firestore_v1 .pipeline_expressions import Field , Variable
@@ -2972,6 +3025,20 @@ def define_example():
29723025 print (r )
29733026
29743027
3028+ def to_array_expression_stage_data ():
3029+ # [START to_array_expression_stage_data]
3030+ client .collection ("Projects" ).document ("project_1" ).set (
3031+ {"id" : "project_1" , "name" : "Alpha Build" }
3032+ )
3033+ tasks = [
3034+ {"project_id" : "project_1" , "title" : "System Architecture" },
3035+ {"project_id" : "project_1" , "title" : "Database Schema Design" },
3036+ ]
3037+ for task in tasks :
3038+ client .collection ("Tasks" ).add (task )
3039+ # [END to_array_expression_stage_data]
3040+
3041+
29753042def to_array_example ():
29763043 # [START to_array_example]
29773044 from google .cloud .firestore_v1 .pipeline_expressions import Field , Variable
@@ -2995,6 +3062,20 @@ def to_array_example():
29953062 print (result )
29963063
29973064
3065+ def to_scalar_expression_stage_data ():
3066+ # [START to_scalar_expression_stage_data]
3067+ client .collection ("Authors" ).document ("author_202" ).set (
3068+ {"id" : "author_202" , "name" : "Charles Dickens" }
3069+ )
3070+ books = [
3071+ {"author_id" : "author_202" , "title" : "Great Expectations" , "rating" : 4.8 },
3072+ {"author_id" : "author_202" , "title" : "Oliver Twist" , "rating" : 4.5 },
3073+ ]
3074+ for book in books :
3075+ client .collection ("Books" ).add (book )
3076+ # [END to_scalar_expression_stage_data]
3077+
3078+
29983079def to_scalar_example ():
29993080 # [START to_scalar_example]
30003081 from google .cloud .firestore_v1 .pipeline_expressions import Field , Variable
@@ -3018,6 +3099,32 @@ def to_scalar_example():
30183099 print (result )
30193100
30203101
3102+ def force_index_example ():
3103+ # [START force_index_example]
3104+ # Note: forceIndex is not currently supported in the Python SDK.
3105+ results = client .pipeline ().collection_group ("customers" ).limit (100 ).execute ()
3106+ # [END force_index_example]
3107+ for result in results :
3108+ print (result )
3109+
3110+
3111+ def force_scan_example ():
3112+ # [START force_scan_example]
3113+ # Note: forceIndex="primary" is not currently supported in the Python SDK.
3114+ results = client .pipeline ().collection_group ("customers" ).limit (100 ).execute ()
3115+ # [END force_scan_example]
3116+ for result in results :
3117+ print (result )
3118+
3119+
3120+ def update_dml_example_data ():
3121+ # [START update_dml_example_data]
3122+ client .collection ("Users" ).document ("userID" ).set (
3123+ {"id" : "userID" , "preferences" : {}, "color" : "#FFFFFF" }
3124+ )
3125+ # [END update_dml_example_data]
3126+
3127+
30213128def pipeline_update_example ():
30223129 # [START pipeline_update]
30233130 from google .cloud .firestore_v1 .pipeline_expressions import Constant , Field , Not
@@ -3035,6 +3142,22 @@ def pipeline_update_example():
30353142 print (snapshot )
30363143
30373144
3145+ def delete_dml_example_data ():
3146+ # [START delete_dml_example_data]
3147+ import datetime
3148+
3149+ client .collection ("Users" ).document ("userID" ).set (
3150+ {
3151+ "id" : "userID" ,
3152+ "address" : {"country" : "USA" , "state" : "CA" },
3153+ "__create_time__" : datetime .datetime .fromtimestamp (
3154+ 946684800000 / 1000 , tz = datetime .timezone .utc
3155+ ),
3156+ }
3157+ )
3158+ # [END delete_dml_example_data]
3159+
3160+
30383161def pipeline_delete_example ():
30393162 # [START pipeline_delete]
30403163 from google .cloud .firestore_v1 .pipeline_expressions import CurrentTimestamp , Field
0 commit comments