I am trying to find a document in a MongoDB collection in a NodeJS environment. Is there any way to do the following?
This is not working:
var foo = function (id) { // find document var document = database.find(id); // do whatever with the document ... } This way creates a block :
var foo = function (id) { // find document var document = database.find(id); while (!database.find.done) { //wait } // do whatever with the document ... } What I want to do :
var foo = function (id) { // find document var document = database.find(id); // pause out of execution flow // continue after find is finished // do whatever with the document ... } I know I can use a callback but is there a simpler way of just "pausing" and then "continuing" in NodeJS/JavaScript? Sorry, I am still pretty new to web development.