title: How do I query in MongoDB with Cloudflare workers?
body: <p>I am trying to query mongodb simple findOne in using mongodb. Cloudflare worker is giving 10ms CPU time but during preview/publish throwing error</p>
  
  <p>I have tried installing these npm modules </p>
  
  <pre><code>npm i mongodb, mongodb-core, dgram, fs
  </code></pre>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  try{
      var db = await MongoClient.connect('mongodb+srv://mongoURL',{ useNewUrlParser: true,useUnifiedTopology: true });
      var dbo = db.db("test");
      var result = await dbo.collection("testcollection").findOne()
      const init = {
          status: 200,
          headers: { "Access-Control-Allow-Origin": "*", 'content-type': 'application/json' },
      }
      return new Response(JSON.stringify(result), init)
  } catch(e) { console.log(e); return new Response(JSON.stringify(result), init)  }
  </code></pre>
  
  <p>Error thrown is here - <a href="https://pastebin.com/xMKKjdZF" rel="noreferrer">https://pastebin.com/xMKKjdZF</a></p>