google-cloud-functions

Count with Firestore Cloud Functions

∥☆過路亽.° 提交于 2020-07-03 08:15:40
问题 I like to count the number of documents in a subcollection with firestore cloud functions. My database looks like that: groups/{groupId}/members/{memberId} I like to count the number of members (memberId) for each group. That means every group can have a different amount of members, and they can increase or decrease flexible. Would be happy about your ideas :-). 回答1: Took me a while to get this working, so thought I'd share it for others to use: 'use strict'; const functions = require(

Do firebase cloud functions involve costs for realtime db and firestore?

巧了我就是萌 提交于 2020-07-03 03:57:05
问题 I am running a cloud function whenever a firestore document is updated. The function reads the document, gets the user IDs and then takes the user token IDs from the realtime db and sends notification. So we have 1 document read here and some download overhead associated with the reads on the realtime db. My question is : If cloud functions reads a node of the realtime db, will the downloads (for the read on the realtime db) be billable? If cloud functions reads a document of firestore, will

Create/update in datastore triggers Cloud function

天大地大妈咪最大 提交于 2020-06-29 06:04:12
问题 I have a database in Google Datastore. I don't know how to use cloud functions, but i want to trigger an event after a creation or an update. Unfortunately the documentation is light on the subject : https://cloud.google.com/appengine/docs/standard/java/datastore/callbacks I don't know how i could use @PostPut to trigger an event as soon as a line is created or updated. Does anyone have a tutorial which a basic example ? thank you 回答1: Dan MacGrath provided an answer to a similar request

How to do integration tests for Firebase HTTP functions with Firestore

你。 提交于 2020-06-28 07:55:39
问题 Trying to write integrations tests for HTTPS function (implemented as an express app) that use Firestore as DB Since its an integration test, I don't want to mock the Firestore DB in this case, however, since they perform network calls, they take time to execute Is there a Firestore local emulator to use in this scenario? There is an option to config Firestore in offline mode, maybe that's the way? Didn't find any documentation in Firebase on this use case AskFirebase 回答1: You have to setup a

Trying to deploy firebase functions, Default service account not found

送分小仙女□ 提交于 2020-06-28 06:52:05
问题 I am trying to upload the following simple function to my firebase console const functions = require('firebase-functions'); exports.helloWorld = functions.https.onRequest((request, response) => { response.send("Hello from Firebase!"); }); However, it fails with the following error: HTTP Error: 400, Default service account 'myfirebase-projecte@appspot.gserviceaccount.com' doesn't exist. Please recreate this account (for example by disabling and enabling the Cloud Functions API), or specify a

How to read local files in the Google Cloud Functions emulator?

岁酱吖の 提交于 2020-06-27 20:28:12
问题 My Google Cloud Function needs to read a local file (an image). I've added the image in the function directory tree, so I have: packages.json src/functions.js lib/functions.js img/shower.png This is the code I'm using to read it: var img = await new Jimp.read("../img/shower.png") Now, when the function triggers, I'm getting this: 2017-03-30T03:00:25.118Z - error: (node:1685) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or

Is it possible to use Anaconda packages as dependencies for Google Cloud Functions?

谁说胖子不能爱 提交于 2020-06-27 10:12:14
问题 I am writing a Google Cloud Function using the Python Runtime and I need to include some dependencies which are not available with pip . As described in the docs here, it should be possible to package local dependencies, however, in my case, I would like to use all the packages of a local Anaconda environment and upload them with the function. Is there a way to do so? Or alternatively, is there a way to specify Anaconda packages in the requirements.txt file instead of using pip ? 回答1: No, it

Run a cron job only once after a set time

与世无争的帅哥 提交于 2020-06-26 07:44:12
问题 I need to run a cron job to perform a specific cloud function after a set interval only once but a bit unsure of how to do it. Is there any way to do this through the current google cloud platform? 回答1: Update following our discussion below through comments: If you want to "change a document in your Firestore database 2 hours after it has been created" you could do as follows: When creating the document in Firestore, save the date/time of creation, e.g. with firebase.firestore.FieldValue

Firebase Cloud Functions - TypeError: Cannot read property 'data' of undefined when data exists

风流意气都作罢 提交于 2020-06-26 06:41:14
问题 I have the following cloud function: exports.keepPostKeysUpdated = functions.database.ref('/posts/{postid}').onWrite(event => { console.log("write on posts..."); console.log(event.previous.params.postID); console.log(event.data.previous.val()); console.log(event.data.previous.val().postID); var postKey = event.data.previous.val().postID; // When a table, category, or region is changed the old upload has to be deleted if (event.data.previous.exists()) { if (event.data.previous.val().table !=

Firebase Cloud Functions - TypeError: Cannot read property 'data' of undefined when data exists

南楼画角 提交于 2020-06-26 06:40:13
问题 I have the following cloud function: exports.keepPostKeysUpdated = functions.database.ref('/posts/{postid}').onWrite(event => { console.log("write on posts..."); console.log(event.previous.params.postID); console.log(event.data.previous.val()); console.log(event.data.previous.val().postID); var postKey = event.data.previous.val().postID; // When a table, category, or region is changed the old upload has to be deleted if (event.data.previous.exists()) { if (event.data.previous.val().table !=