[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore Numeric Transforms #34

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add snippets for numeric transforms
  • Loading branch information
samtstern committed Mar 21, 2019
commit 95ecccee3f681ab3a61dc3719c3d417b9058fe5e
2 changes: 1 addition & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"author": "Firebase (https://firebase.google.com/)",
"license": "Apache-2.0",
"dependencies": {
"firebase-admin": "^5.0.0"
"firebase-admin": "^7.1.1"
}
}
6 changes: 3 additions & 3 deletions firestore/extend-with-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "Cloud Functions and Firestore",
"main": "index.js",
"dependencies": {
"@google-cloud/firestore": "^0.16.1",
"firebase-admin": "^6.0.0",
"firebase-functions": "^1.0.0"
"@google-cloud/firestore": "^1.1.0",
"firebase-admin": "^7.1.1",
"firebase-functions": "^2.2.1"
}
}
28 changes: 26 additions & 2 deletions firestore/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ function updateDocumentArray(db) {
});
}

function updateDocumentIncrement(db) {
// [START update_document_increment]
var admin = require('firebase-admin');
// ...
var washingtonRef = db.collection('cities').doc('DC');

// Atomically incrememnt the population of the city by 50.
samtstern marked this conversation as resolved.
Show resolved Hide resolved
// Note that increment() with no arguments increments by 1.
var popIncrement = washingtonRef.update({
population: admin.firestore.FieldValue.increment(50)
});
// [END update_document_increment]

return popIncrement.then(res => {
console.log('Increment: ' + res);
});
}

function updateDocumentMany(db) {
// [START update_document_many]
var cityRef = db.collection('cities').doc('DC');
Expand Down Expand Up @@ -391,7 +409,9 @@ function transaction(db) {
var transaction = db.runTransaction(t => {
return t.get(cityRef)
.then(doc => {
// Add one person to the city population
// Add one person to the city population.
// Note: this could be done without a transaction
// by updating the population using FieldValue.increment()
var newPopulation = doc.data().population + 1;
t.update(cityRef, {population: newPopulation});
});
Expand Down Expand Up @@ -992,7 +1012,11 @@ describe('Firestore Smoketests', () => {
return updateDocumentArray(db);
});

it('should update many document', () => {
it('should update a document using numeric transforms', () => {
return updateDocumentIncrement(db);
});

it('should update many documents', () => {
return updateDocumentMany(db);
});

Expand Down
6 changes: 3 additions & 3 deletions firestore/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/firestore": "^0.21.0",
"firebase-admin": "^6.5.1"
"@google-cloud/firestore": "^1.1.0",
"firebase-admin": "^7.1.1"
},
"devDependencies": {
"mocha": "^3.3.0"
"mocha": "^6.0.2"
}
}
4 changes: 2 additions & 2 deletions firestore/solution-aggregation/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^6.0.0",
"firebase-functions": "^1.0.1"
"firebase-admin": "^7.1.1",
"firebase-functions": "^2.2.1"
},
"private": true
}
6 changes: 3 additions & 3 deletions firestore/solution-deletes/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.5",
"firebase-tools": "^4.2.1"
"firebase-admin": "^7.1.1",
"firebase-functions": "^2.2.1",
"firebase-tools": "^6.5.0"
}
}
4 changes: 2 additions & 2 deletions firestore/solution-scheduled-backups/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"axios": "^0.18.0",
"dateformat": "^3.0.3",
"express": "^4.16.4",
"googleapis": "^34.0.0"
"googleapis": "^38.0.0"
},
"devDependencies": {
"prettier": "^1.14.3"
"prettier": "^1.16.4"
}
}
4 changes: 2 additions & 2 deletions functions/stackdriver-logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@google-cloud/logging": "^4.2.0",
"firebase-functions": "^2.1.0"
"@google-cloud/logging": "^4.5.1",
"firebase-functions": "^2.2.1"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"lint": "find . -type f -name \"*.js\" -not -path \"*node_modules*\" | xargs eslint"
},
"devDependencies": {
"eslint": "^4.17.0",
"eslint-config-google": "^0.9.1",
"lerna": "^2.8.0"
"eslint": "^5.15.3",
"eslint-config-google": "^0.12.0",
"lerna": "^3.13.1"
}
}