Skip to content

Commit 95eccce

Browse files
committed
Add snippets for numeric transforms
1 parent 20d7b8c commit 95eccce

File tree

9 files changed

+45
-21
lines changed

9 files changed

+45
-21
lines changed

auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"author": "Firebase (https://firebase.google.com/)",
66
"license": "Apache-2.0",
77
"dependencies": {
8-
"firebase-admin": "^5.0.0"
8+
"firebase-admin": "^7.1.1"
99
}
1010
}

firestore/extend-with-functions/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Cloud Functions and Firestore",
44
"main": "index.js",
55
"dependencies": {
6-
"@google-cloud/firestore": "^0.16.1",
7-
"firebase-admin": "^6.0.0",
8-
"firebase-functions": "^1.0.0"
6+
"@google-cloud/firestore": "^1.1.0",
7+
"firebase-admin": "^7.1.1",
8+
"firebase-functions": "^2.2.1"
99
}
1010
}

firestore/main/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ function updateDocumentArray(db) {
269269
});
270270
}
271271

272+
function updateDocumentIncrement(db) {
273+
// [START update_document_increment]
274+
var admin = require('firebase-admin');
275+
// ...
276+
var washingtonRef = db.collection('cities').doc('DC');
277+
278+
// Atomically incrememnt the population of the city by 50.
279+
// Note that increment() with no arguments increments by 1.
280+
var popIncrement = washingtonRef.update({
281+
population: admin.firestore.FieldValue.increment(50)
282+
});
283+
// [END update_document_increment]
284+
285+
return popIncrement.then(res => {
286+
console.log('Increment: ' + res);
287+
});
288+
}
289+
272290
function updateDocumentMany(db) {
273291
// [START update_document_many]
274292
var cityRef = db.collection('cities').doc('DC');
@@ -391,7 +409,9 @@ function transaction(db) {
391409
var transaction = db.runTransaction(t => {
392410
return t.get(cityRef)
393411
.then(doc => {
394-
// Add one person to the city population
412+
// Add one person to the city population.
413+
// Note: this could be done without a transaction
414+
// by updating the population using FieldValue.increment()
395415
var newPopulation = doc.data().population + 1;
396416
t.update(cityRef, {population: newPopulation});
397417
});
@@ -992,7 +1012,11 @@ describe('Firestore Smoketests', () => {
9921012
return updateDocumentArray(db);
9931013
});
9941014

995-
it('should update many document', () => {
1015+
it('should update a document using numeric transforms', () => {
1016+
return updateDocumentIncrement(db);
1017+
});
1018+
1019+
it('should update many documents', () => {
9961020
return updateDocumentMany(db);
9971021
});
9981022

firestore/main/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"@google-cloud/firestore": "^0.21.0",
14-
"firebase-admin": "^6.5.1"
13+
"@google-cloud/firestore": "^1.1.0",
14+
"firebase-admin": "^7.1.1"
1515
},
1616
"devDependencies": {
17-
"mocha": "^3.3.0"
17+
"mocha": "^6.0.2"
1818
}
1919
}

firestore/solution-aggregation/functions/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"logs": "firebase functions:log"
1010
},
1111
"dependencies": {
12-
"firebase-admin": "^6.0.0",
13-
"firebase-functions": "^1.0.1"
12+
"firebase-admin": "^7.1.1",
13+
"firebase-functions": "^2.2.1"
1414
},
1515
"private": true
1616
}

firestore/solution-deletes/functions/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"author": "",
1010
"license": "Apache-2.0",
1111
"dependencies": {
12-
"firebase-admin": "^6.0.0",
13-
"firebase-functions": "^2.0.5",
14-
"firebase-tools": "^4.2.1"
12+
"firebase-admin": "^7.1.1",
13+
"firebase-functions": "^2.2.1",
14+
"firebase-tools": "^6.5.0"
1515
}
1616
}

firestore/solution-scheduled-backups/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"axios": "^0.18.0",
1717
"dateformat": "^3.0.3",
1818
"express": "^4.16.4",
19-
"googleapis": "^34.0.0"
19+
"googleapis": "^38.0.0"
2020
},
2121
"devDependencies": {
22-
"prettier": "^1.14.3"
22+
"prettier": "^1.16.4"
2323
}
2424
}

functions/stackdriver-logging/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "",
77
"license": "Apache-2.0",
88
"dependencies": {
9-
"@google-cloud/logging": "^4.2.0",
10-
"firebase-functions": "^2.1.0"
9+
"@google-cloud/logging": "^4.5.1",
10+
"firebase-functions": "^2.2.1"
1111
}
1212
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"lint": "find . -type f -name \"*.js\" -not -path \"*node_modules*\" | xargs eslint"
1111
},
1212
"devDependencies": {
13-
"eslint": "^4.17.0",
14-
"eslint-config-google": "^0.9.1",
15-
"lerna": "^2.8.0"
13+
"eslint": "^5.15.3",
14+
"eslint-config-google": "^0.12.0",
15+
"lerna": "^3.13.1"
1616
}
1717
}

0 commit comments

Comments
 (0)