Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-551

Synchronous operations

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            isaacrg Isaac Reid-Guest
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: