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

138
Views
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 answers
Answer question

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 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!