您好,我很难让我的Promises.all
仅触发一次。您能帮我调试此代码,以便仅打印一次。
Firestore模式为:
/As/${ADoc}/Bs/${BDoc}/Cs/${CDoc}/Ds/${DsDocs}
我需要获取${DsDocs.id}
出现的次数。
感谢您的帮助。
var DsCount = []
var allPromises = []
const APromise = db.collection("As").get().then((ADocs) => {
allPromises.push(APromise)
ADocs.forEach((ADoc) => {
const BPromise = db.collection(`As/${ADoc.id}/Bs`).get().then((BDocs) => {
allPromises.push(BPromise)
BDocs.forEach((BDoc) => {
CPromise = db.collection(`As/${ADoc.id}/Bs/${BDoc.id}/Cs`).get().then((CDocs) => {
allPromises.push(CPromise)
CDocs.forEach((CDoc) => {
const CVBPromise = db.collection(`As/${ADoc.id}/Bs/${BDoc.id}/Cs/${CDoc.id}/Ds`).get().then((DsDocs) => {
allPromises.push(CVBPromise)
DsDocs.forEach((DsDoc) => {
if(DsCount[DsDoc.id] == undefined){
DsCount[DsDoc.id] = 1
}else{
DsCount[DsDoc.id] = DsCount[DsDoc.id] + 1
}
Promise.all(allPromises).then(results => {
console.log(DsCount)
})
})
})
})
})
})
})
})
})