简体   繁体   English

如何批量插入ouchdb文件?

[英]How to insert couchdb documents in bulk?

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. 我为他们提供了一次上传包含大量调整内容的CSV文件的功能。

On the server they are inserting items into couch one by one, like this: 在服务器上,他们正在将物品逐一插入沙发中,如下所示:

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);
}

The couch URL is built dynamically. 沙发URL是动态构建的。

req.body contains the properties for a single item. req.body包含单个项目的属性。

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 request.post call into a loop as is, but I imagine that's not going to be very performant. 我可以按原样将request.post调用放入循环中,但是我想那不会表现得很好。

I just need pointed in the right direction for bulk insertion into couch via its REST API. 我只需要指出正确的方向,即可通过其REST API将其批量插入沙发。 Thanks! 谢谢!

您可以使用批量文档API插入(甚至更新)多个文档。

您可以使用nano-有批量插入选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM