首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google修复云函数-字段路径问题

Google修复云函数-字段路径问题
EN

Stack Overflow用户
提问于 2022-07-20 21:24:50
回答 1查看 51关注 0票数 2

我正在尝试构建云防火墙计划函数,它选择具有特定条件的所有文档(日期小于Date.now),然后在两个字段中逐个更新它们。

函数已成功部署,但在执行时将返回以下错误:

代码语言:javascript
复制
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) 

我对Java脚本不太了解,但我使用的语法与颤振代码相同,而且它在应用程序中工作正常。

下面的js代码有什么问题?

代码语言:javascript
复制
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");
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-21 00:33:45

基于上面的代码,Firestore将您的操作符<读取为field_path。您的field_path后面应该有一个逗号,并使操作符字符串。见下面的示例代码:

代码语言:javascript
复制
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": ""});
  }
});

您还可以检查有关如何执行Fi还原查询的文档:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73058300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档