title: Can not connect Azure Functions to MongoDB (created in azure)
body: <p>I have a MongoDB setup on azure, and I am tring to connect to it via azure function.</p>
  
  <p>These are the steps I took:</p>
  
  <ol>
  <li>Creating a Simple Azure Function</li>
  <li>Installed the MongoDB Driver on Azure, To install the MongoDB Node.js driver, I went go to .scm.azurewebsites.net, and clicked on 'Debug Console' -> 'PowerShell'.</li>
  <li>I Navigated to the D:\home\site\wwwroot directory and clicked on the plus icon to create a new file called package.json.</li>
  <li><p>I Created and saved the below package.json file.</p>
  
  <pre><code>  {
    "name": "nameofunction",
    "dependencies": {
     "mongodb": "3.x"
    }
  }
  </code></pre></li>
  <li>Next, I ran <code>npm install</code> from the shell.</li>
  <li><p>From the Azure Function I should be able to connect to MongoDB and execute a query using the below code.</p>
  
  <pre><code>const  mongodb = require('mongodb');
  const  url = "mongodb://cosmod:  &lt;PASSWORD&gt;==@cosmodb.documents.azure.com:10255/?ssl=true&amp;replicaSet=globaldb";
  
  module.exports = async function (context, req) {
      mongodb.connect(url, function(error, client) {        
        if (error) throw error;
        var dbo = client.db("mydb");
        dbo.createCollection("customers", function(err, res) {
           if (err) throw err;
           context.log("Collection created!");
           db.close();
        });         
     });
   };
  </code></pre></li>
  </ol>
  
  <p>My code is throwing up a <code>Status: 500 Internal Server Error</code></p>
  
  <p>The more I look at the code, the more i can not understand why this should not work. 
  The <code>package-lock.json</code>has all the dependencies loaded after I ran <code>npm install</code> in the shell.</p>
  
  <p>I appreciate any help in resolving this.</p>