Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  177] [ 2]  / answers: 1 / hits: 15262  / 10 Years ago, tue, january 20, 2015, 12:00:00

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.


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.


req.body contains the properties for a single item.


/


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.


I just need pointed in the right direction for bulk insertion into Couch via its REST API.


More From » node.js

 Answers
19

You can use the bulk document API to insert (and even update) multiple documents.


[#68149] Saturday, January 17, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tobyl

Total Points: 598
Total Questions: 110
Total Answers: 114

Location: Vietnam
Member since Sat, Feb 12, 2022
2 Years ago
tobyl questions
Tue, Aug 10, 21, 00:00, 3 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
;