【发布时间】:2021-01-29 18:10:04
【问题描述】:
我正在使用 Firebase 实时数据库和 Firebase 云功能(在 Typescript 中)。 下面是我的数据库节点的结构:
订单节点:
orders
|- {Push ID}
|--billing_id
|--orders_id
发货节点:
shippings
|- {Push ID}
|-- billing_id
|-- user_id
我的函数观察“orders”节点的变化并获取“billing_id”的值。
注意:此 billing_id 与存储在 “运输”节点。此 billing_id 将始终出现在“shippings”节点中。
在下一步中,我想定位包含确切 billing_id 的 shipping 节点并获取 user_id。 以下是代码(最短版本):
export const orderEmail = functions.database.ref('/orders/{pushId}')
.onCreate((snapshot,context)=>{
const original = snapshot.val(); //Stores values from the newly created orders node
const billing_id = original.billing_id; // Stores the billing_id from the newly created orders node
//Need help from here.
var db = admin.database();
var val1:any;
db.ref(`/shippings/{pushId}/${billing_id}`).once("value") //Next what do I need to do?
});
编辑 1:
尝试了 Neelavar 建议的解决方案。以下是我在部署该函数时遇到的警告和错误。
WARNING: A:/HN/functions/src/index.ts:79:9 - Forbidden 'var' keyword, use 'let' or 'const' instead
WARNING: A:/HN/functions/src/index.ts:79:13 - Identifier 'db' is never reassigned; use 'const' instead of 'var'.
ERROR: A:/HN/functions/src/index.ts:86:24 - Shadowed name: 'snapshot'
WARNING: A:/HN/functions/src/index.ts:149:9 - Forbidden 'var' keyword, use 'let' or 'const' instead
WARNING: A:/HN/functions/src/index.ts:149:13 - Identifier 'options' is never reassigned; use 'const' instead of 'var'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ lint: `tslint --project tsconfig.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\RIYASREE'S_PC\AppData\Roaming\npm-cache\_logs\2020-10-15T14_18_07_047Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
注意:如果需要任何其他信息,请告诉我。 另外,请提供详细的解决方案,因为我是 Firebase 和 Typescript 的新手。
【问题讨论】:
标签: typescript firebase firebase-realtime-database google-cloud-functions