Skip to content

Commit cc9b15b

Browse files
authored
Array union/remove snippets (#8)
1 parent 60c7e7f commit cc9b15b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

firestore/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
firebase-debug.log

firestore/test.firestore.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ describe("firestore", () => {
410410
// [END update_document]
411411
});
412412

413+
it("should update an array field in a document", () => {
414+
// [START update_document_array]
415+
var washingtonRef = db.collection("cities").doc("DC");
416+
417+
// Atomically add a new region to the "regions" array field.
418+
washingtonRef.update({
419+
regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
420+
});
421+
422+
// Atomically remove a region from the "regions" array field.
423+
washingtonRef.update({
424+
regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
425+
});
426+
// [END update_document_array]
427+
});
428+
413429
it("should delete a document", () => {
414430
return output =
415431
// [START delete_document]

0 commit comments

Comments
 (0)