Skip to content

Commit 5bd8a20

Browse files
committed
docs(firestore): clarify update/upsert target path Javadoc and Upsert sample
1 parent 578beed commit 5bd8a20

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎java-firestore/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,13 +1225,13 @@ public Pipeline delete() {
12251225
/**
12261226
* Performs an update operation using documents from previous stages.
12271227
*
1228-
* <p>This method updates the documents in place based on the data flowing through the pipeline.
1229-
* To specify transformations, use {@link #update(Selectable...)}.
1228+
* <p>This method updates existing documents based on the data flowing through the pipeline. To
1229+
* specify transformations, use {@link #update(Selectable...)}.
12301230
*
1231-
* <p>Each document is written back to its existing path. The stored document is replaced by the
1232-
* pipeline document, so fields removed by earlier stages (for example, with {@link
1233-
* #removeFields(String, String...)}) are also removed from the stored document. This stage does
1234-
* not create documents: documents that don't exist are skipped.
1231+
* <p>Each document is written to the path given by its {@code __name__} field. The stored
1232+
* document is replaced by the pipeline document, so fields removed by earlier stages (for
1233+
* example, with {@link #removeFields(String, String...)}) are also removed from the stored
1234+
* document. This stage does not create documents: target documents that don't exist are skipped.
12351235
*
12361236
* <p>Example 1: Update a collection's schema by adding a new field and removing an old one.
12371237
*
@@ -1245,7 +1245,7 @@ public Pipeline delete() {
12451245
* .get();
12461246
* }</pre>
12471247
*
1248-
* <p>Example 2: Update documents in place with data from literals.
1248+
* <p>Example 2: Update documents with data from literals.
12491249
*
12501250
* <pre>{@code
12511251
* Map<String, Object> updateData = new HashMap<>();
@@ -1381,10 +1381,10 @@ public Pipeline upsert(Upsert upsert) {
13811381
}
13821382

13831383
/**
1384-
* Writes each document produced by the previous stages back to its own path, after adding the
1385-
* given fields. The document is created if it doesn't exist and replaced if it does; stored
1386-
* fields are not merged. A document without a {@code __name__} field fails with {@code
1387-
* INVALID_ARGUMENT}.
1384+
* Writes each document produced by the previous stages to the path given by its {@code __name__}
1385+
* field, after adding the given fields. The document is created if it doesn't exist and replaced
1386+
* if it does; stored fields are not merged. A document without a {@code __name__} field fails
1387+
* with {@code INVALID_ARGUMENT}.
13881388
*
13891389
* <p>Example:
13901390
*

‎java-firestore/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Update.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import javax.annotation.Nullable;
2828

2929
/**
30-
* A pipeline stage that updates, in place, the documents produced by the previous stages.
30+
* A pipeline stage that updates existing documents in the database using the documents produced by
31+
* the previous stages. Each input document's {@code __name__} field identifies the target document
32+
* to update.
3133
*
3234
* <p>Use with {@link com.google.cloud.firestore.Pipeline#update(Update)}, or call {@link
3335
* com.google.cloud.firestore.Pipeline#update()} / {@link

‎java-firestore/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Upsert.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
* <p>Example:
5050
*
5151
* <pre>{@code
52-
* // Set "status" on each matching document and write it back to its own path.
52+
* // Set "status" on each matching document and write it to the path given by its __name__ field.
5353
* firestore.pipeline()
5454
* .collection("books")
5555
* .where(field("rating").greaterThan(4))
56-
* .upsert(new Upsert().withAdditionalFields(constant("Featured").as("status")))
56+
* .addFields(constant("Featured").as("status"))
57+
* .upsert()
5758
* .execute()
5859
* .get();
5960
* }</pre>
@@ -79,15 +80,15 @@ private Upsert(
7980

8081
/**
8182
* Creates an upsert stage with no additional fields, no target collection and no document ID
82-
* expression, so each document is written back to its own path.
83+
* expression, so each document is written to the path given by its {@code __name__} field.
8384
*/
8485
public Upsert() {
8586
this((ImmutableList<Selectable>) null, null, null, InternalOptions.EMPTY);
8687
}
8788

8889
/**
8990
* Creates an upsert stage that adds the given fields to each input document before it is written
90-
* back to its own path.
91+
* to the path given by its {@code __name__} field.
9192
*
9293
* @param additionalFields Fields to add to each input document. A field with the same name as an
9394
* existing input field overwrites that field.

0 commit comments

Comments
 (0)