0

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 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 – mmontano Oct 29 '17 at 08:06
  • I did take a look at that and did not find any that covered my question as they were different situations. Mine is trying to replace lowdb calls (synchronous) with mongodb calls (asynchronous callback) without rewriting the application. I was able to finally find through searching other keywords an answer: deasync . This library using their loopWhile function was the answer I needed. Now this caused another issue but was able to fix that by making the require call in the same scope as the loopWhile and the variable it uses to check must be defined after the require statement. – mmontano Nov 21 '17 at 16:52

0 Answers0