google-cloud-functions

How to update a collection using cloud function?

假如想象 提交于 2020-01-16 18:55:32
问题 I would like to update the score using a cloud function I've tried this so far exports.rate = functions.https.onRequest((request, response) => { admin .firestore() .collection() .where("index", "==", request.index) .get() .then(snap => { snap.forEach(x => { const newRating = x.data().score + request.value; firebase .firestore() .collection() .doc(x.id) .update({ score: newRating }); }); }); }); 回答1: The following should work: exports.rate = functions.https.onRequest((request, response) => {

how to make get request firebase cloud functions

眉间皱痕 提交于 2020-01-16 18:45:28
问题 I am developing an app and I want to send my user coordinate from firestore to locationiq.com to get details and then write it in firestore I am using firebase cloud function to make GET request but I think it fails can someone help me with the code I am getting this error Function returned undefined, expected Promise or value const functions = require('firebase-functions'); const request = require('request'); const admin = require ('firebase-admin'); admin.initializeApp(); // Create and

Error: could not handle the request with Google Cloud Function and Express

元气小坏坏 提交于 2020-01-16 18:01:07
问题 this is my code. Why when I go to the url of my cloud function I receive this message :"Error: could not handle the request" and I didn't see "Hello World!" ? Thanks exports.simple = (req,res) => { var express = require('express'); var https = require('https'); var bodyParser = require('body-parser'); var app = express(); module.exports = app; return app.get('/', (req, res) => res.send("Hello World!")) .then((result) => { console.log("DONE",result); console.log("Delete opportunity"); })

Having a promise issue with my google cloud function

旧城冷巷雨未停 提交于 2020-01-16 18:01:05
问题 I have an http trigger in cloud functions that is working, however I am getting some logs come back in a weird order. I am pretty sure I have not executed the promises correctly. here is the code: exports.createGame = functions.https.onRequest((req, res) => { return cors(req, res, () => { // Check for POST request if (req.method !== "POST") { res.status(400).send('Please send a POST request'); return; } const createGame = admin.firestore().collection('games') generatePin() function

Is this the correct way of returning a ES6 promise in firebase cloud functions?

[亡魂溺海] 提交于 2020-01-16 16:26:30
问题 I have a cloud function similar to this: exports.verifyEmail = functions.https.onCall((data, context) => { // data contains session_id (doc id where otp is stored) and otp return new Promise((resolve, reject) => { admin.firestore().collection('verification').doc(data.session_id).get().then(doc => { if(data.otp === doc.data().otp){ return resolve() } else { return reject({message: 'OTP did not match'}) } }).catch(err => { return reject({message: err.message}) }) }) }) I read this method on a

Is this the correct way of returning a ES6 promise in firebase cloud functions?

随声附和 提交于 2020-01-16 16:26:02
问题 I have a cloud function similar to this: exports.verifyEmail = functions.https.onCall((data, context) => { // data contains session_id (doc id where otp is stored) and otp return new Promise((resolve, reject) => { admin.firestore().collection('verification').doc(data.session_id).get().then(doc => { if(data.otp === doc.data().otp){ return resolve() } else { return reject({message: 'OTP did not match'}) } }).catch(err => { return reject({message: err.message}) }) }) }) I read this method on a

How do I install npm packages on Google Cloud Functions?

不想你离开。 提交于 2020-01-16 14:56:21
问题 I'm trying to create a simple function that: fetches a JSON file from a public URL does a little number crunching and spits out an answer. I figured that Google Cloud Functions would be the perfect fit since I can code in JS and don`t have to worry about server deployment, etc. I've never really used nodejs / npm so maybe this is the issue, but I tried reading online and they just mention npm install package-name I'm not sure where I can do this on the Google Cloud Functions page. I'm

How to load 2 different Firestore docs in one 'onUpdate' Cloud Function?

强颜欢笑 提交于 2020-01-16 14:03:25
问题 I am trying to make an "onUpdate" function that loads the document that has been updated. Then I want to load another document using the data received by the wildcards. So to summarize I want to access the document that was updated and one more that is in the same collection. I want : /userProfiles/{doc1}/employees/{doc2} AND /userProfiles/{doc1} . I can get them both but when I try to use the data from one, it doesn't read the previous data and gives me a ReferenceError . The end goal is to

How do I send notifications from Google Cloud(GCP) via Firebase to an Android app

我只是一个虾纸丫 提交于 2020-01-16 11:26:18
问题 I know how to send messages from Firebase cloud messaging portal to an android device. But my server runs on Google Cloud, I do gcloud app deploy from my local machine and the app logic gets deployed on Google Cloud. Now, I want to send notifications, based on the data stored as Entities in GCP Datastore, to an Android App. Notification messages can be sent from Firestore-Cloud Messaging portal to an Android device, if I could harness this Firestore Cloud Messaging API in my GCP logic, then

Firebase - How to disable user using Cloud Function?

梦想与她 提交于 2020-01-16 09:43:21
问题 I am trying to work out an enable/disable user cloud function. When using the admin SDK to disable the user, I get the response: that the disabled property is read only . Can someone help me out? The data that is passed to the function, is the user ID. export const disableUser = functions.https.onCall((data, context) => { console.log(data); admin.auth().updateUser(data, { disabled: true }).then(() => { admin.firestore().collection('users').doc(data).update({ disabled: true}) .then(() => {