I have a realtime database from Firebase, where data is stored in single strings not in objects. Problem is foreach loop executes at last, where as it need to be run first (i mean sequential). It comes out from the loop without performing its jobs.
exports.room_server = functions.database.ref(`/${Role.ROOM_REQUEST}/{room}`)
.onCreate((snapshot,context)=>{
// her ref.once is refrence to another node of database
ref.limttolast(3).once("value",function(snap){
snap.forEach(function (usr) {
adm = usr.val();
console.log("admin " + adm);
});
}).catch();
console.log(" cl " + adm);
});
// cl undefined is shown first
// then it comes
// admin abc
// admin you
// admin me
//result should be
//admin abc
//admin you
//admin me
//cl me