title: How to insert couchdb documents in bulk?
body: <p>I'm tasked with modifying a legacy app so that users can upload payroll adjustments in bulk. Currently they have to fill out a form and input the data item by item, hitting submit after each one. I'm giving them the ability to upload a CSV file containing tons of adjustments at once.</p>
  
  <p>On the server they are inserting items into couch one by one, like this:</p>
  
  <pre><code>function wsapiPOST(req, res, next) {
    var path = req.path.substr(6)
      , url = couchPath + path + requestUtil.buildQueryString(req);
  
    request.post({
      url: url,
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify(req.body)
    },function (err, resp, body) {
      if (err) {
        if (resp) {
          res.writeHead(resp.statusCode);
          res.end(body);
        } else { // This would happen if the request timed out
          res.writeHead(408);
          res.end('timeout');
        }
      }
    }).pipe(res);
  }
  </code></pre>
  
  <p>The couch URL is built dynamically.</p>
  
  <p><code>req.body</code> contains the properties for a single item.</p>
  
  <p><img src="https://i.imgur.com/XOET9TR.png" alt=""></p>
  
  <p>I'm new to couch but I'm not sure how to send multiple documents for insertion in a single operation. I could throw the <code>request.post</code> call into a loop as is, but I imagine that's not going to be very performant.</p>
  
  <p>I just need pointed in the right direction for bulk insertion into couch via its REST API. Thanks!</p>