@@ -43,15 +43,13 @@ public Quickstart(String projectId) throws Exception {
4343 // [START firestore_setup_client_create]
4444 // Option 1: Initialize a Firestore client with a specific `projectId` and
4545 // authorization credential.
46- // [START fs_initialize_project_id]
4746 // [START firestore_setup_client_create_with_project_id]
4847 FirestoreOptions firestoreOptions =
4948 FirestoreOptions .getDefaultInstance ().toBuilder ()
5049 .setProjectId (projectId )
5150 .setCredentials (GoogleCredentials .getApplicationDefault ())
5251 .build ();
5352 Firestore db = firestoreOptions .getService ();
54- // [END fs_initialize_project_id]
5553 // [END firestore_setup_client_create_with_project_id]
5654 // [END firestore_setup_client_create]
5755 this .db = db ;
@@ -65,10 +63,8 @@ public Quickstart() {
6563
6664 // Option 2: Initialize a Firestore client with default values inferred from
6765 // your environment.
68- // [START fs_initialize]
6966 Firestore db = FirestoreOptions .getDefaultInstance ().getService ();
7067 // [END firestore_setup_client_create]
71- // [END fs_initialize]
7268 this .db = db ;
7369 }
7470
@@ -84,7 +80,6 @@ Firestore getDb() {
8480 void addDocument (String docName ) throws Exception {
8581 switch (docName ) {
8682 case "alovelace" : {
87- // [START fs_add_data_1]
8883 // [START firestore_setup_dataset_pt1]
8984 DocumentReference docRef = db .collection ("users" ).document ("alovelace" );
9085 // Add document data with id "alovelace" using a hashmap
@@ -98,11 +93,9 @@ void addDocument(String docName) throws Exception {
9893 // result.get() blocks on response
9994 System .out .println ("Update time : " + result .get ().getUpdateTime ());
10095 // [END firestore_setup_dataset_pt1]
101- // [END fs_add_data_1]
10296 break ;
10397 }
10498 case "aturing" : {
105- // [START fs_add_data_2]
10699 // [START firestore_setup_dataset_pt2]
107100 DocumentReference docRef = db .collection ("users" ).document ("aturing" );
108101 // Add document data with an additional field ("middle")
@@ -115,7 +108,6 @@ void addDocument(String docName) throws Exception {
115108 ApiFuture <WriteResult > result = docRef .set (data );
116109 System .out .println ("Update time : " + result .get ().getUpdateTime ());
117110 // [END firestore_setup_dataset_pt2]
118- // [END fs_add_data_2]
119111 break ;
120112 }
121113 case "cbabbage" : {
@@ -135,7 +127,7 @@ void addDocument(String docName) throws Exception {
135127 }
136128
137129 void runQuery () throws Exception {
138- // [START fs_add_query ]
130+ // [START firestore_setup_add_query ]
139131 // asynchronously query for all users born before 1900
140132 ApiFuture <QuerySnapshot > query =
141133 db .collection ("users" ).whereLessThan ("born" , 1900 ).get ();
@@ -152,11 +144,10 @@ void runQuery() throws Exception {
152144 System .out .println ("Last: " + document .getString ("last" ));
153145 System .out .println ("Born: " + document .getLong ("born" ));
154146 }
155- // [END fs_add_query ]
147+ // [END firestore_setup_add_query ]
156148 }
157149
158150 void retrieveAllDocuments () throws Exception {
159- // [START fs_get_all]
160151 // [START firestore_setup_dataset_read]
161152 // asynchronously retrieve all users
162153 ApiFuture <QuerySnapshot > query = db .collection ("users" ).get ();
@@ -174,7 +165,6 @@ void retrieveAllDocuments() throws Exception {
174165 System .out .println ("Born: " + document .getLong ("born" ));
175166 }
176167 // [END firestore_setup_dataset_read]
177- // [END fs_get_all]
178168 }
179169
180170 void run () throws Exception {
0 commit comments