Skip to content

Commit fef57ce

Browse files
authored
Add field increment (firebase#13)
2 parents 411002d + 2793c77 commit fef57ce

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ Before you submit your pull request consider the following guidelines:
105105
```
106106
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
107107

108-
* Build your changes locally to ensure all the tests pass:
109-
110-
```shell
111-
gulp
112-
```
108+
* Open the local index.html file in your browser to ensure all the tests pass.
113109

114110
* Push your branch to GitHub:
115111

firestore/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
<script>mocha.setup('bdd')</script>
1414

15-
<script src="https://www.gstatic.com/firebasejs/5.5.5/firebase.js"></script>
16-
<script src="https://www.gstatic.com/firebasejs/5.5.5/firebase-firestore.js"></script>
15+
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase.js"></script>
16+
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-firestore.js"></script>
1717
<script src="test.firestore.js"></script>
1818
<script src="test.solution-arrays.js"></script>
1919
<script src="test.solution-counters.js"></script>

firestore/test.firestore.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,18 @@ describe("firestore", () => {
423423
// [END update_document_array]
424424
});
425425

426+
it("should update a document using numeric transforms", () => {
427+
// [START update_document_increment]
428+
var washingtonRef = db.collection('cities').doc('DC');
429+
430+
// Atomically increment the population of the city by 50.
431+
// Note that increment() with no arguments increments by 1.
432+
washingtonRef.update({
433+
population: firebase.firestore.FieldValue.increment(50)
434+
});
435+
// [END update_document_increment]
436+
})
437+
426438
it("should delete a document", () => {
427439
return output =
428440
// [START delete_document]
@@ -450,6 +462,9 @@ describe("firestore", () => {
450462
throw "Document does not exist!";
451463
}
452464

465+
// Add one person to the city population.
466+
// Note: this could be done without a transaction
467+
// by updating the population using FieldValue.increment()
453468
var newPopulation = sfDoc.data().population + 1;
454469
transaction.update(sfDocRef, { population: newPopulation });
455470
});

0 commit comments

Comments
 (0)