【发布时间】:2020-06-03 00:42:52
【问题描述】:
我有一个文档,其中有一个名为relatives 的集合。在云功能中,我有 onUpdate() 的此文档的侦听器。更改某些内容后,我想访问文档中的该集合。还有集合中的文档relatives。
这是它的样子:
我尝试过的
exports.UpdateLocations = functions.firestore.document("users/{userID}").onUpdate((change, context) => {
const userEmail = change.after.data().email;
const prevLocation = change.before.data().userLocation;
const currentLocation = change.after.data().userLocation;
if (prevLocation === currentLocation) return 0;
if (change.after.data().userType.toString() === "Patient") {
const userLocation = change.after.data().userLocation;
const relatives = change.after.data().relatives;
console.log("User's Current Location: " + userLocation);
console.log("Relatives : "+relatives );
}
return;
});
我想访问亲属及其文件。所以我可以搜索和比较字段并有目的地更新它们。
【问题讨论】:
-
与其用文字描述你想要做什么,你能用代码展示你已经做了什么以及你卡在哪里了吗?这样就更有可能有人告诉你哪里出错了,或者为你完成。
-
我没有给出代码块的原因是我基本上坚持访问文档中的集合。我改变了我的结构,我以前的所有代码都变得一团糟。但是如果给它带来改变,我现在就添加它。
标签: firebase google-cloud-firestore google-cloud-functions