许多博客建议切换到Cloud Firestore,因为它很容易且安全可靠。来自实时数据库,返回使用Function + RD时,很容易浏览文档触发器,例如ref.parent
我的设置是这样的:
- 用户数
- {用户身份}
- last_seen:“数据”
- {形式}
- {formid}
但是,我使用添加了一个文档触发器onCreate,并且我想获取以下值last_seen:
exports.updateUser = functions.firestore.document('users/{userId}/forms/{formid}').onCreate((snap, context) => {
const newValue = snap.data();
console.log("test value : " + newValue.test); // works
console.log("form id: " + context.params.formid); // works
console.log("user last seen : " + newValue.last_seen); // doesn't work, can't access the parent collection data
});
Run Code Online (Sandbox Code Playgroud) node.js firebase google-cloud-functions google-cloud-firestore