【发布时间】:2020-07-26 15:21:29
【问题描述】:
我正在努力使用更新集合组“place_users”上的“存在”属性的云功能。
我的查询没有按“存在”== true 过滤条目。它曾经在客户端工作,但我将它切换到云功能,它不再过滤。所有文件都被退回。
exports.updatePoiPresence = functions.https.onCall((data: any, context: any) => {
return new Promise((resolve, reject) => {
return store.collectionGroup("place_users",
(ref: any) => ref
.where("user_id", "==", context.auth.uid)
.where("day_stamp", "<", data.start_of_day / 1000)
.where("presence", "==", true))
.get()
.then(
(q_snapshot: any) => {
return q_snapshot.forEach((snapshot: any) => {
functions.logger.log("no docs value data fct:", snapshot.data())
snapshot.ref.update({
presence: false
})
.then((a: any) => {
resolve("ok");
})
.catch((error: any) => {
functions.logger.log("error survenue", error);
reject("Rejet pas identifie")
})
});
})
});
});
我为该 collectionGroup 创建了一系列索引: (我不知道在什么情况下使用哪个,因为我一直通过控制台单击索引创建向导,而没有考虑它们的用途。
【问题讨论】:
-
您在哪里记录我们可以在您的屏幕截图中看到的“no docs value data fct”字符串?
-
嗨@RenaudTarnec,我刚刚编辑了我的帖子
-
您似乎试图将代码从 Angular 移植到运行 Cloud Functions 的后端代码中。这是行不通的,因为 SDK 有不同的语法。此外,无需在这里创建新的承诺。所有 API 都已经处理了 Promise - 只需使用 API 提供的那些即可。
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions