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

165
Visualizações
Google Firestore Cloud Function - problem with field path

I am trying to build cloud firestore scheduled function that select all documents with a certain condition (date less than Date.now) and then to update them one by one in two fields.

function is deployed successfully but when executed it returns the below error:

Error: Value for argument "fieldPath" is not a valid field path. Paths can only be specified as strings or via a FieldPath object.
at Object.validateFieldPath (/workspace/node_modules/@google-cloud/firestore/build/src/path.js:605:15)
at CollectionReference.where (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1059:16)
at /workspace/index.js:8:12
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:74:23)
at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:144:25
at processTicksAndRejections (node:internal/process/task_queues:96:5) 

I don't know so much with Java script but I am using the same syntax with flutter code and it is working correctly in the application.

what is the problem with the below js code?

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const database = admin.firestore();
exports.testscheduledFunction = functions.pubsub.schedule("every 1 minutes").onRun(
      (context) => {
      database.collection("BusinessProfilesCollection")
      .where("Profile_pinning_ed" < admin.firestore.Timestamp.now())
      .get().then((snapshot) => {
        let i = 0;
        let tempid = "";
        console.log(snapshot.docs.length);
        for (i; i<snapshot.docs.length; i++) {
          tempid = snapshot.docs[i].id;
          database.collection("BusinessProfilesCollection").doc(tempid)
              .update({
                "Profile_pinning_status": "No",
                "Profile_pinning_ed": ""});
        }
      });
  return console.log(
      "Cloud Functions: Business Profiles Pinning is updated successfully");
});
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Based on the code above, Firestore is reading your operator < as a field_path. Your field_path should be followed by a comma and make the operator string. See sample code below:

database.collection("BusinessProfilesCollection")
// Fixed query.
.where("Profile_pinning_ed", "<", admin.firestore.Timestamp.now())
.get().then((snapshot) => {
  let i = 0;
  let tempid = "";
  console.log(snapshot.docs.length);
  for (i; i<snapshot.docs.length; i++) {
    tempid = snapshot.docs[i].id;
    database.collection("BusinessProfilesCollection").doc(tempid)
        .update({
          "Profile_pinning_status": "No",
          "Profile_pinning_ed": ""});
  }
});

You may also check this documentation on how to perform Firestore queries:

  • Simple queries
about 4 years ago · Santiago Trujillo 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