【发布时间】:2018-07-01 21:33:03
【问题描述】:
我想查询DocumentReference 的两个子集合。
我尝试了以下操作:
var promise1 = admin.firestore().collection(`players/${id}/collection1`).get();
var promise2 = admin.firestore().collection(`players/${id}/collection2`).get();
return Promise.all(promise1, promise2)
但问题是,通过执行以下操作,我得到以下错误:
TypeError: (var)[Symbol.iterator] 不是函数 在 Function.all (本机) 在exports.onSubmission.functions.firestore.document.onCreate (/user_code/index.js:671:20)
所以,我尝试将它们嵌套如下,效果很好。
return admin.firestore().collection(`players/${id}/collection1`).get().then(foundersSnapshot => {
return admin.firestore().collection(`players/${id}/collection2`).get().then(metricsSnapshot => {
但是,在部署时我收到警告说
避免嵌套承诺
那么,在这种情况下,最佳做法是什么?我宁愿通过Promise.all 做,但它不起作用。此外,它会在then(results => { 中输出两个集合作为结果因此,在这种情况下,我可以安全地将results[0] 视为“collection1”而将`results[1] 视为“collection2”吗?
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions