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

178
Visualizações
Have an empty docs in querySnaphsot when trying to get data with firebase

I recently developped a firebase schedule function to retrieve data on every monday. I tested it during the previous days and it was working correctly. However, this morning, I discovered that my query wasn't able anymore to retrieve data as it used to do. I now have an empty array at QuerySnapshot.docs. You can find my code below:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();

exports.scheduledFunction = functions.pubsub.schedule("0 0 * * 1").onRun(async () => {
  console.log("start");
  const querySnapshotnext = await db.collection("Next_challenges").orderBy("createdAt").get();

  console.log("Let see querySnapshot :", querySnapshotnext); //it works, I can see QuerySnapshot object
  console.log("Let see docs :", querySnapshotnext.docs); //have an empty array [] even if it should not, it wasn't empty few days ago
  console.log("let see the data of the first doc : ", querySnapshotnext.docs[0].data()); //is of course undefined
  
  return null;
});

You can find my database below with the doc that is normally selected:

enter image description here

The rules of my databases are the following :

enter image description here

I don't really understand why my code isn't working anymore, I think it's certainly related to some parameters stuffs and don't really know how I could debug this by myself so don't hesitate to give me some tips so I can be more autonomous with firebase. Thank you :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firestore's documentation has a note that says,

An orderBy() clause also filters for existence of the given field. The result set will not include documents that do not contain the given field.

You have .orderBy("createdAt") in your query but there isn't any createdAt field in the documents (at least the one in screenshot). Did you change your document structure recently that is causing this issue?


Also the Admin SDK bypasses any security rules so I'd recommend setting them to false if you don't need to access data directly from client.

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