Firestore 云函数 - 路径中的访问变量

Firestore cloud functions - access variable in path

所以我的数据库中有这个架构:test1/{test1Id}/test2/{test2Id}

每当添加新数据库时,我都想在云函数中与我的数据库进行交互:

exports.test = functions.firestore
  .document('test1/{test1Id}/test2/{test2Id}')
  .onCreate(async (testsnap, context) => {
    console.log(testsnap.id);
    console.log(test1Id);
  });

但是 test1Id 就是 undefined。我怎样才能访问它?

先谢谢了。

你必须使用

context.params.test1Id

所有参数都保存在上下文对象下