title: Output bindings not picked up or present in Javascript Azure Functions
body: <p>I'm having a bit of difficulty getting my simple Azure Function to dump a JSON payload into a CosmosDB. Here is the desired setup:</p>
  
  <pre><code>[HTTP TRIGGER] -&gt; [JS FUNCTION] -&gt; [INSERT JSON TO COSMOS DB]
  </code></pre>
  
  <p>I've added a cosmosDB output binding via <strong>Integrate</strong> in the web console</p>
  
  <p><a href="https://i.stack.imgur.com/DhVNe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DhVNe.png" alt="enter image description here"></a></p>
  
  <p>I know this part works because it will auto-create the collection upon running.</p>
  
  <p>However, this is where my success ends. </p>
  
  <p>I've included my code here. Maybe there is something obvious that I have missed:</p>
  
  <p><strong>function.json</strong></p>
  
  <pre><code>{
    "bindings": [
      {
        "authLevel": "function",
        "type": "httpTrigger",
        "direction": "in",
        "name": "req"
      },
      {
        "type": "http",
        "direction": "out",
        "name": "res"
      },
      {
        "type": "documentDB",
        "name": "outputDocument",
        "databaseName": "outDatabase",
        "collectionName": "MyCollection",
        "createIfNotExists": true,
        "connection": "mydocdb_DOCUMENTDB",
        "direction": "out"
      }
    ],
    "disabled": false
  }
  </code></pre>
  
  <p><strong>index.js</strong></p>
  
  <pre><code>module.exports = function (context, req) {
      context.log('JavaScript HTTP trigger function processed a request.');
  
      context.bindings.outputDocument = {test: "hello world"}
      context.done();
  };
  </code></pre>
  
  <p><strong>snippet output of context.log(context)</strong>
  I've also peeked into the context variables, and it seems that the outbund bindings not there. I would have expected to see outputDocument here:</p>
  
  <pre><code>bindings: 
     { req: 
        { originalUrl: 'https://log-ugly-url-here',
          method: 'POST',
          query: [Object],
          headers: [Object],
          body: [Object],
          params: {},
          rawBody: '{\n    "name": "Azure"\n}' } },
    bind: [Function],
  </code></pre>
  
  <p>Executing this function in the portal gets a 200 OK, but no values show up in my cosmosdb collections.</p>
  
  <p>No errors are shown anywhere. </p>
  
  <p>Can anyone see what I might have missed?</p>
  
  <p><strong>Updates</strong>
  It was recommended that I try to use JSON.stringify() around the payload, per <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-documentdb#documentdb-api-output-binding-sample" rel="nofollow noreferrer">this document</a>: </p>
  
  <pre><code>context.bindings.outputDocument = JSON.stringify({test: "hello world"});
  </code></pre>
  
  <p>However, this has not resolved the issue. I've noticed that the documentation under the binding config sections does not recommend this strategy. </p>
  
  <p><strong>Update - Nov. 8, 2017 (10:12 AM)</strong></p>
  
  <p>I was using the Data Explorer blade in azure to see if there were results in my collections. I decided to use Robo 3T Mongo client. Now, when I query the collection I get the following error:</p>
  
  <pre><code>Error: error: {
      "_t" : "OKMongoResponse",
      "ok" : 0,
      "code" : 1,
      "errmsg" : "Unknown server error occurred when processing this request.",
      "$err" : "Unknown server error occurred when processing this request."
  }
  </code></pre>
  
  <p>I tried to look at the logs for this cosmosdb, but no errors show up.</p>