title: Showing that node shell is async and mongo shell is not
body: <p>So I have a mongodb setup and I have some test data in it. I want to be able to show that the mongo shell runs our script sync and node runs our script async. I have setup the two following js files which I got while doing a Mongo University course. This is really more of a test so that I understand what's going on. I am going to cd into the directory where I have mongo installed using npm and where the scripts are also at. Then I will call these scripts, I will call the <code>mongoshell.js</code> using </p>
  
  <pre><code>&gt;mongo mongoshell.js
  </code></pre>
  
  <p>and nodeshell.js using:</p>
  
  <pre><code>&gt;node nodeshell.js
  </code></pre>
  
  <p>Here are the two scripts:</p>
  
  <p><strong>mongoshell.js</strong></p>
  
  <pre><code>//Find one document in our collection
  var doc = db.allClasses.findOne();
  
  print('before');
  
  //Print the result
  printjson(doc);
  
  print('after');
  </code></pre>
  
  <p>And the result I get from running that in the shell is:
  <img src="https://i.stack.imgur.com/2rfnq.png" alt="enter image description here"></p>
  
  <p>So my thinking here is that the print command is something that would return quicker than the query to mongo. BY placing a before and after print and everything coming out in the right order, it must be synchronous.</p>
  
  <p>Next I have the <strong>nodeshell.js</strong></p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  
  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db){
      if (err) throw err;
  
      //Find one document in our collection
      db.collection('allClasses').findOne({}, function(err, doc){
          //Print the result
          console.dir(doc);
  
          //close the DB
          db.close();
      });
  });
  
  setTimeout(function(){
      console.dir("10 Milliseconds!");
  }, 10);
  setTimeout(function(){
      console.dir("100 Milliseconds!");
  }, 100);
  </code></pre>
  
  <p>And the result from the console is:</p>
  
  <p><img src="https://i.stack.imgur.com/sPzrq.png" alt="enter image description here"></p>
  
  <p>My thinking here is that I have determined that mongo usually takes between 10 and 100 milliseconds to return my data. If I put two print commands with timeouts one at 10 ms and one at 100 ms one should fire before the json is returned BECAUSE THE NODE SHELL IS ASYNC and the other should fire after..</p>
  
  <p><strong>MY QUESTION:
  Does this hillbilly test actually show that each of the shells are what they are. Synchronous and Asynchronous? if Yes cool, if not, why?</strong></p>