Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
Firebase REST get data

After watching Firebase Cloud Function Tutorial - REST API Part 1 | Diligent Dev, I have spent several hours trying to understand how to get the entire record that was posted into firestore. Here is index.js code:

const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const admin = require("firebase-admin");
admin.initializeApp();
const app = express();
app.use(cors({origin: true}));


app.post("/", async (req, res) => {
    const user = req.body;
    await admin.firestore().collection("users").add(user);
    res.status(201).send(JSON.stringify(user));
  }); 

The JSON data I posted was:

{"id":123, "name":"Tony Stark", "email":"ironMan@MarvelComics.com"}

In this get, the id is returned but I can't seem to access the other properties that are part of the record (example name: Tony Stark)?

  app.get("/:id", async (req, res) => {
    const snapshot = await
    admin.firestore().collection("users").doc(req.params.id).get();
    const userId = snapshot.id;
    const userData = snapshot.data():
    constole.log(userData);
    res.status(200).send(JSON.stringify({id: userId, ...userData}));
  });

There must be a simple solution but console.log(userData) is not the answer! :-(

Almost forgot to say, my request from the browser is passing the user id as a query parameter, in this example localhost:5001/projectReference/user/1 and I also tried with the Cloud Firestore document id (.../user/XRAwtfj9FSubeCArvUtQ). In each case I see in the browser the JSON string {"id":"the_value_requested"} but no userData.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

What does console.dir(userData) output? That should help you see what's in the returned object.

Are you confident that name and email are avtually present on the record in Firebase? It's possible your retrieval is working as expected but the data expected isn't there.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda