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

211
Visualizações
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
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