-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
-
Empty show more show less
When using mongodb for node, the developer is in effect compelled to use callback functions, often resulting in many nested callback functions, making code ugly, and inconvenient.
I believe it would be really useful if the node native driver supported operating synchronously, meaning that the results from a query could be saved to a variable, and then used appropriately, rather than warranting a callback function.
*In example:*
synchronous.js
var result = db.collection("posts").find().toArray(); /*DO STUFF WITH RESULTS HERE*/
is easier to use than
asynchronous.js
var collection = db.collection("posts"); // Locate all the entries using find collection.find().toArray(function(err, results) { /*DO STUFF WITH RESULTS HERE*/ });
Crucially, any synchronous action could still act akin to an asynchronous one, but without needing another callback function.
I would love to hear thoughts and ideas on this.