title: Mongodb Nodejs: return undefined after callback of an exported function
body: <p>I'm new to the Node.js world. I've connected node to my MongoDB server. Now I want to write my module for MongoDB's CRUD operations but when I call <code>find</code>, it returns <code>undefined</code>.</p>
  
  <p>How can I solve this problem?</p>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>    var MongoClient = require('mongodb').MongoClient;
      var express = require('express');
      var app = express();
      var url = "mongodb://localhost:27017/movie";
      var result;
      var crud = require('./crud.js');
  
      MongoClient.connect(url, function(err, db) {
        if (err) throw err;
        var dbo = db.db("movie");
        var test=crud.findAll(db,dbo,"test");
        console.log(test);
        });
  
      var server = app.listen(8081, function () {
      var host = server.address().address;
      var port = server.address().port;
      console.log("Listening on "+host+":"+port);
      })
  </code></pre>
  
  <p><strong>crud.js</strong></p>
  
  <pre><code>    exports.findAll = function(db, dbo, collection){
      dbo.collection(collection).find({}).toArray(function(err,result){
      if (err) throw err;
          db.close();
          return result;
      });
      }
  </code></pre>