Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Las funciones de Firebase se bloquean al acceder a firestore

¿Podría encontrar un error en el siguiente código?

 const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(); exports.GetShort = functions.https.onRequest((request, response) => { response.header("Access-Control-Allow-Origin", "*"); longURL = request.query.long functions.logger.info("url is - " ,longURL) SaveToDB(longURL) }) function SaveToDB(link){ functions.logger.info("here") admin.firestore().collection("url").where("urlNames","array_contains",link).get().then( function(querySnapshot){ functions.logger.info("snap, " ,querySnapshot) querySnapshot.forEach(function(doc) { functions.logger.info("things : " ,doc.id, " => ", doc.data()) // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); } ) .catch(function(error) { functions.logger.info("Error getting documents: ", error); }); }

Después de presionar la función anterior, los registros de funciones de base de fuego muestran registros hasta "aquí" . Después de eso, se bloquea sin más registros/stacktrace.

a continuación se muestra el contenido de packages.json del directorio de funciones.

 { "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "lint": "eslint .", "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "14" }, "main": "index.js", "dependencies": { "firebase-admin": "^9.8.0", "firebase-functions": "^3.14.1" }, "devDependencies": { "eslint": "^7.6.0", "eslint-config-google": "^0.14.0", "firebase-functions-test": "^0.2.0" }, "private": true }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Le sugiero amablemente que vea los 3 videos sobre "Promesas de JavaScript" de la serie de videos de Firebase para ver cómo administrar el ciclo de vida de una función en la nube y la forma de lidiar con llamadas a métodos asincrónicos.

En particular, para una función de nube HTTPS , debe finalizarla con send() , redirect() o end() .

Entonces su código podría adaptarse de la siguiente manera:

 exports.GetShort = functions.https.onRequest((request, response) => { response.header("Access-Control-Allow-Origin", "*"); const longURL = request.query.long; functions.logger.info("url is - ", longURL) SaveToDB(longURL) .then(() => { response.status(200).send('Saved to DB'); }) .catch(error => { // See video series response.status(500).send(error); }) }) function SaveToDB(link) { functions.logger.info("here") return admin.firestore().collection("url").where("urlNames", "array_contains", link).get() .then(querySnapshot => { functions.logger.info("snap, ", querySnapshot) querySnapshot.forEach(function (doc) { functions.logger.info("things : ", doc.id, " => ", doc.data()) // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); // => Here, depending on your real functional requirements, you may need to use Promise.all() }); return null; } ).catch(function (error) { functions.logger.info("Error getting documents: ", error); // Throw an error }); }
about 4 years ago · Juan Pablo Isaza Report

0

Bueno, encontré el problema. A veces, las cosas tontas hacen la mayor parte del ruido. En lugar de "array-contains", escribí "array_contains".

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!