title: Modifying MongoDB to allow cross origin requests
body: <p>I am relatively new to MongoDB so I am still getting used to it. </p>
  
  <p>Currently I am trying to post a json object to mongo from the client side using the code below in javascript.</p>
  
  <pre><code>var addUserButton = document.getElementById('add-user');
  var userNameInput = document.getElementById('name');
  
  addUserButton.onclick = function() {
      var newUser = new Object();
      newUser.name = userNameInput.value;
      var newUserJson = { 'name': newUser.name};
      $.post('127.0.0.1:27017/test', newUserJson);
  };
  </code></pre>
  
  <p>When ever I run this code though I get  error stating:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load %3127.0.0.1:27017/test. Cross origin
    requests are only supported for protocol schemes... etc</p>
  </blockquote>
  
  <p>I read up on this and was wondering if adding the following CORS handler to mongoDB would fix this. If it is correct, how would I go about adding this to MongoDB? I could not find documentation on how to add this CORS handler to mongo</p>
  
  <pre><code>function handleCors(req, res, callback) {
  
      res.setHeader('Access-Control-Allow-Origin', '*')
      res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE,OPTIONS');
      res.setHeader('Access-Control-Allow-Headers', 'Authorization');
  
      // CORS OPTIONS request, simply return 200
      if (req.method == 'OPTIONS') {
          res.statusCode = 200;
          res.end();
          callback.onOptions();
          return;
      }
  
      callback.onContinue();
  };
  </code></pre>