title: MongoDB call inside feathers.js Hook
body: <p>I want to get the info from a collection inside a feathers.js hook. 
  How can i make the hook wait, until the mongodb call is complete? At the moment it sends the hook without waiting for the call to finish, i tried it with returns and promieses, but nothing worked</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Connection URL
  const url = 'mongodb://localhost:27017/db';
  
  //Use connect method to connect to the server
  
  module.exports = function(hook) {
    MongoClient.connect(url, function(err, db) {
    const userCollection = db.collection('question');
  
    userCollection.count().then(function(N) {
  
      const R = Math.floor(Math.random() * N)
  
      const randomElement = userCollection.find().limit(1).skip(R).toArray(function(err, docs) {
      console.log("Found the following records");
      console.log(docs)
      //update hook with data from mongodb call
      hook.data.questionid = docs._id;
    });
    })
    })
  };</code></pre>
  </div>
  </div>
  </p>