title: Using Async/await with mongoose
body: <p>I was taking this advance NodeJS course by Stephen Grinder where we were testing out caching in Redis. </p>
  
  <p>As I run my application and reach the given route, I am thrown with this error </p>
  
  <blockquote>
    <p>DeprecationWarning: Mongoose: mpromise (mongoose's default promise
    library) is deprecated, plug in your own promise library instead:
    <a href="http://mongoosejs.com/docs/promises.html" rel="nofollow noreferrer">http://mongoosejs.com/docs/promises.html</a></p>
  </blockquote>
  
  <p>And other one which looks like this </p>
  
  <blockquote>
    <p>UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
    error originated either by throwing inside of an async function
    without a catch block, or by rejecting a promise which was not handled
    with .catch(). (rejection id: 1) [0] (node:11896) [DEP0018]
    DeprecationWarning: Unhandled promise rejections are deprecated. In
    the future, promise rejections that are not handled will terminate the
    Node.js process with a non-zero exit code. [0] serving from MongoDb</p>
  </blockquote>
  
  <p>Now, as mentioned, I went through and had a look at it very vaguely and it seems that their documentation does not talk about async and await. </p>
  
  <p>This is the api route which is throwing the error </p>
  
  <pre><code>  app.get('/api/blogs', requireLogin, async (req, res) =&gt; {
      const redis = require('redis')
      const redisURL = 'redis://127.0.0.1:6379';
      const  client = redis.createClient(redisURL);
      const util = require('util')
      client.get = util.promisify(client.get)
      const cachedBlog = await client.get(req.user.id) 
      if (cachedBlog)  return res.send(JSON.parse(cachedBlogs))
      console.log("serving from MongoDb")
      const blogs = await Blog.find({_user: req.user.id})
      client.set(req.user.id, JSON.parse(blogs))
      res.send(blogs);
    });
  </code></pre>
  
  <p>To be specific this line here </p>
  
  <pre><code> const blogs = await Blog.find({_user: req.user.id})
  </code></pre>
  
  <p>Where </p>
  
  <pre><code>const Blog = mongoose.model('Blog');
  </code></pre>
  
  <p>Note: To explain cache in a nutshell, Stephen Grinder have purposely set it inside a root.</p>
  
  <p><strong>[Question:]</strong> Can someone please tell me how can I use async/await (like what I have currently done inside the route) without being thrown any errors?</p>