title: Getting issue while fetching data from mongodb using async/await
body: <p>I am using node.js express framework to create REST API and trying to convert my code from callbacks to Async/Await methods with basic .then() promise using <a href="https://morioh.com/p/84e8042c2185" rel="nofollow noreferrer">artical</a>  . so while implementing code getting error as <code>SyntaxError: await is only valid in async function</code></p>
  <p>I am new to javascript and not understand what is cause this issue. I have below folder structure</p>
  <pre><code> MAIN APP
      ├── app.js
      ├── controllers
      │   └── UserController.js
      ├── routes
      │   └── User.js
      └── util
          ├── AuthUtil.js
          ├── Helpers.js
          ├── RestUtil.js
          └── wallet.js
   
  </code></pre>
  <p>My backend API controller function is below</p>
  <pre><code>Getone: async (req, res, next) =&gt; {
      try {
      MongoClient.connect(config.Database.DFARM.connectString, function(err, client) {
         assert.equal(null, err);
         const db = client.db(config.Database.DFARM.dbName);
        console.log('********db**********',db)
         //Step 1: declare promise
  
          var myPromise = () =&gt; {
             return new Promise((resolve, reject) =&gt; {
  
                db
                .collection('User')
                .find(query)
                .limit(1)
                .toArray(function(err, docs) {
                   err
                      ? reject(err)
                      : resolve(docs[0]);
                 });
             });
          };
         //await myPromise
         var result = await myPromise();
         //continue execution
         client.close();
         console.log('********result**********',result)
  
      //    res.json(result);
      }); //end mongo client
      } catch (e) {
         next(e)
      }
      }
  </code></pre>
  <p>My router</p>
  <pre><code>router.get('/getone/:id', function (req, res, next) {
      controller.Getone(req, res, next);
  });
  </code></pre>