我正在try 构建云firestore计划功能, Select 具有特定条件(日期小于date.now)的所有文档,然后在两个字段中逐个更新它们.

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

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脚本了解不多,但我对flatter代码使用相同的语法,它在应用程序中正常工作.

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

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");
});

推荐答案

基于上述代码,Firestore正在将运算符<作为field\u路径读取.field_路径后面应该跟一个逗号,并使运算符成为字符串.见下面的示例代码:

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": ""});
  }
});

您还可以查看本文档,了解如何执行Firestore查询:

Javascript相关问答推荐

当试图显示小部件时,使用者会出现JavaScript错误.

如何用拉威尔惯性Vue依赖下拉?

如何通过将实例方法的名称传递给具有正确类型的参数的继承方法来调用实例方法?

使用POST请求时,Req.Body为空

在浏览器中触发插入事件时检索编码值的能力

Nextjs 13.4 Next-Auth 4.2登录(&Quot;凭据&,{});不工作

使用Ace编辑器对子组件实例的native-element 进行Angular 获取时面临的问题

在不扭曲纹理的情况下在顶点着色器中旋转UV

如何在Jest中模拟函数

如何让SVG图标在被点击和访问后改变 colored颜色 ,并在被访问后取消点击时恢复到原来的 colored颜色 ?

是否有静态版本的`instanceof`?

为什么我的InDesign Java脚本不能完全工作?

如何在预览中显示html+css与数据URL?

如何解析/data/build中的Angularnode_modules/chart.js/dist/Chart.js?

我不能将每个产品单独添加或删除到Collection 列表中

在脚本设置中使用Vue3 v-html,无需额外的换行标记

在promise.all之前选中NULL

Chart.js折线图动态更改其y轴

如何在应用内Chromium浏览器中启用通知模块?(未捕获ReferenceError:未定义通知)

导航栏中显示项目的方式有问题