Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
Getting a specific document from query Using Firebase Cloud functions

Im trying to get a user from a users collection with the most votes on a timed function. Ive been following the examples they have on the documentation, but still having trouble. Any thoughts?

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();

exports.testData = functions.pubsub.schedule("30 14 * * *")
    .timeZone("America/New_York")
    .onRun((context) => {
      const test = admin.firestore().collection("users").
          orderBy("votes").limit(1);

      try {
        console.log("document data:", test.data());
      } catch (e) {
        console.log("Error getting document:", e);
      }
      return null;
    });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your code hasn't executed the query at all. It is just building a query object, then calling a method data() which doesn't exist on that object (likely causing your code to crash). I suggest reviewing the documentation to learn how to use get() to execute the query. It returns a promise that you must handle correctly.

return test.get()
    .then(snapshot => ...)
    .catch(error => ...)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda