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