I would assume that if I run the following code in my node console.
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db){
if (err) throw err;
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);
That if I consistently (10 out of 10 times) get the following output:
That this illustrates that not only does the mongo query take between 10 and 100 ms to return my data, but that my node console executes my code in an asynchronous fashion.
Question: Is this correct?
I have one alternate question.
If I wait for a very long time to execute this script, let's say 20 minutes, leaving my mongod.exe running. And then run the script. Sometimes I get the following output.
I can understand the data return coming in last, I'm assuming because it takes longer than 100 ms for some reason probably to do with connectivity or since I waited so long it takes longer because mongod is idle or something along those lines....
Question 2: Why would the message function that is timed out longer show up first?
I know there has to be a silly reason.