Full async request to Mongodb via node.js

Before I render a page, I have to make several requests to mongodb. Here is how I do it now (db.js is my database processing layer):

db.findUser(objid, function(result1){
  db.findAuthor(objid, function(result2){
    db.findSmthElse (objid, function(result3){
      res.render('template', {
        user: result1,
        author: result2,
        smthelse: result2
      });
    });
  });
});

I do suppose such methos kills the idea of async. However I need to call res.render only after all the requests are processed. How to launch it async? Should I use async library as it was advised here: multiple async mongo request in nodejs or are there any more suitable solutions? Thanks.

I do suppose such methos kills the idea of async

No they don't. That is precisely how asynchronous I/O is supposed to work. However, I do feel your pain with chaining multiple async calls. Before you know it, you can have 6 or 7 nested anonymous async functions.

There are two criteria I would use before I consider using a library like async or promise.

  1. Number of functions - this is somewhat subjective, but how many looks frustrating to you? You currently have 3 and if you are likely to stick to three, then another library is probably not worth the complexity. Again, this is subjective and totally my opinion.
  2. Dependencies - if each method builds on the results of the previous one, then they cannot run in parallel. However, in your case, the three database queries are independent and only the res.render call depends on the chained functions. Your use case is a good candidate for async.parallel in this regard.

I hope this helps you make your decision