This is a server side implementation and the code needs to wait execution till data is returned. I cannot use data in console.log implementation but need it in an array of objects to be processed outside of the function block.
I have seen many answers to my question but they all involve console.log. I do not need to write them to a console. I need to use the array outside of the promise scope.
db.collection("star").find().toArray (err,result) -> console.log result
i need to use the result out here. I need the array of objects here. I do not need to write to a log. I need for the execution to wait for the data and return it like this:
stars = db.collection("star").find().toArray (err,result) -> return result
I need it execution to wait and return the array in the stars variable to be processed. This is not a browser situation but server side javascript.