Skip to content

Commit

Permalink
Merge pull request #345 from ahmedissa/master
Browse files Browse the repository at this point in the history
Use stream for exporting collections
  • Loading branch information
dozoisch authored May 31, 2017
2 parents c7d7ca3 + a06149e commit fbbe9c7
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/routes/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,13 @@ var routes = function (config) {
};

exp.exportCollection = function (req, res) {
req.collection.find().toArray(function (err, items) {
res.setHeader('Content-disposition', 'attachment; filename=' + req.collectionName + '.json');
res.setHeader('Content-type', 'application/json');
var aItems = [];
for (var i in items) {
var docStr = bson.toJsonString(items[i]);
aItems.push(docStr);
}

res.write(aItems.join(os.EOL));
res.end();
});
res.setHeader('Content-disposition', 'attachment; filename=' + req.collectionName + '.json');
res.setHeader('Content-type', 'application/json');
req.collection.find().stream({
transform: function (item) {
return bson.toJsonString(item) + os.EOL;
},
}).pipe(res);
};

exp.exportColArray = function (req, res) {
Expand Down

0 comments on commit fbbe9c7

Please sign in to comment.