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

207
Views
Not getting results from cloud functions by .where()

I am using this code to get data from a collection by comparing

/* eslint-disable */
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
const database = admin.firestore();

exports.checkForPending = functions.pubsub.schedule('* * * * *').onRun(async (context) 
=> {
   var currentTime = admin.firestore.Timestamp.now();
   var total; //getting time from firebase server
    var firebase_time = admin.firestore.Timestamp.now(); // {'_seconds': 123456, 
_nanoseconds: 123000000}
    // Convert map of nanoseconds and seconds to milliseconds
    var firebase_seconds_to_milliseconds = firebase_time._seconds * 1000; // 123456000
    var firebase_nanoseconds_to_milliseconds = Math.round(firebase_time._nanoseconds / 
1000000) //123
    var milliseconds = firebase_seconds_to_milliseconds + 
firebase_nanoseconds_to_milliseconds;
    var firebase_month = firebase_time.toDate().getMonth();

    var unix_to_date_before_buffer = new Date(milliseconds); 
    var unix_to_date_after_buffer = new Date(milliseconds);
    // var unix_to_date = new Date(total);
     unix_to_date_before_buffer.setSeconds(0); //coverted from 6:38:23 to 6:38:00
     unix_to_date_after_buffer.setSeconds(0);
     unix_to_date_after_buffer.setMinutes(unix_to_date_after_buffer.getMinutes() + 1);//coverted from 6:38:23 to 6:39:00
  //Want to edit month in this timestamp;
  const query = 
database.collection("users").doc('IELTS').collection('IELTS').where("next", '>=', unix_to_date_before_buffer).where("next", '<=', unix_to_date_after_buffer); // comparing here
 const snapshot = await query.get();
 snapshot.forEach(doc => {
    console.log(doc.id, '=>', doc.data().name),
    queryTest2 = database.collection('rest');
    queryTest2.add(
    {
    'executed': true,
    'name': doc.data().name
    }
    )
  });

  return null;
});    

The am not getting any results in the console. I am wondering why? I didn't see any new collection 'rest' formed. The time in the collection of parameter 'next' was 6:38:24 in the collection in the example.

What I am trying to build - I am making an app for an institute. I am registering users and making a collection which looks like - collection (here 'date' is the date of registration and 'next' is the time when The pay will automatically change to 0 because of the starting of next month.) Now I am running a cloud function that is checking every day if 'next' is equal to the current time of server, then I want to execute something (add a user to a new collection called 'pending'.) and update 'next' to the next month. which should look like this - edited-paramter

about 4 years ago · Juan Pablo Isaza
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!