FirebaseError: [code=resource-exhausted]: Too many outstanding requests

Viewed 650

I have a collection of size >1000 documents , in each document a uid is stored which is used in getting data from other collection. The other collection has further subcollections. I am pushing the object of data into an array . here is the code

let arr =[];
let db = firebase.firestore();
 db.collection('Collection1').orderBy('timestamp','desc').onSnapshot(snapshot=>{
snapshot.forEach(async doc=>{
let obj = doc.data();
let uid = obj.uid;
let objM ={}
let obj2={}
let obj3 ={}
 await  db.collection('Collection2').doc(uid).get().then(docs=>{
obj2 = docs.data()

}).then(async ()=>{
 await db.collection('Collection2').doc(uid).collection('subcollection1').doc(uid).get().then(docs=>{
 obj3 = docs.data()

}).then(async ()=>{
await  db.collection('Collection2').doc(uid).collection('subcollection2').doc(uid).get().then(docs=>{
 obj4 = docs.data()

}).then(()=>{
objM={...obj,...obj2,...obj3,...obj4}
arr.push(objM)
}
})
})
})

the above code works fine but very slow when Collection1 is of small size, also it gives following error when collection's size is increased

Using maximum backoff delay to prevent overloading the backend.

and

Uncaught (in promise) FirebaseError: Too many outstanding requests.

how can i remove the error and also reduce the loading time.

0 Answers
Related