I have the following (sample) array:
pages = [ {
"name" : "Hello",
"id" : 123
},{
"name" : "There",
"id" : 987
},{
"name" : "Great",
"id" : 555
} ];
I want to save every object in this array as Document in a Collection. Therefor I have the following function:
exports.testSaveFacebookPages = functions.https.onRequest((req, res) => {
cors(req, res, () => {
let userUid = req.body.uid
// pages array is available here...
const PagesRef = admin.firestore().collection(`/users/${userUid}/pages/`)
return pages.forEach(function(page, index){
PagesRef.doc(`p${index}`).update(page, { merge: true })
});
res.status(200).send('Pages saved successfull!');
}); // cors...
}); // exports...
When the function get executed, it saves the pages to the Firestore :) But it seems the function getting executed in a loop. The logging say:
Function execution started
Function execution took 60002 ms, finished with status: 'timeout'
I've readed: Cloud Functions with Firestore error "Dealine Exceeded" and https://firebase.google.com/docs/functions/terminate-functions
But I could not find any Cloud Function example with a forEach. Any help would be great!