ForEach not working in Firebase Cloud Functions

So basically I want to migrate my data from Firebase Realtime Database to Cloud Firestore. This is what I’ve been trying for now:'/', async (req, res) => {   // const receivedTimestamp =   const telegramText = req.body     && req.body.message     &&     &&     && req.body.message.from     && req.body.message.from.first_name    if (telegramText && req.body.message === '/migrate') { const snapAllUsersData = await admin.database().ref(`/Data/users/`).once("value").then(async function (allUsers: any) {   let usersMigrated= 0   allUsers.forEach((eachUser: any) => {     usersMigrated= usersMigrated + 1     const currentName = eachUser.val().name     const currentCountry = eachUser.val().country                           admin.firestore().collection('users').doc(currentName.toLowerCase()).set({ "name": currentName, "country": currentCountry }, { merge: true }).then(() => {       console.log(`${usersMigrated} | ${currentName} | ${currentCountry}`)     }).catch((err) => {       console.log(err)     })   });   console.log(`${usersMigrated} migrated successfully`) }).catch((errGettingData) => {   console.log(errGettingData)   return })  }) 

There are no logs in the Firebase Console Either 🙁

Similar code works in Node.JS projects which I run on my GCP VM. SNot working in here….

Database Structure:

Data:   users:     User1:       name: "Dharmaraj",       country: "IN"     User8:       name: "Qwerty",       country: "US" 

PS: there is no issue in path and any case sensitivity issue

EDIT: So now I ran the very SAME CODE in a NODE.JS project without Cloud Functions…. Just ran it in local terminal and it worked buttery smooth and all data got migrated in within 5 seconds…

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.