Skip to content

Commit 57e2e64

Browse files
committed
[dbviewer] remove double aggregation
1 parent eb56a34 commit 57e2e64

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

plugins/dbviewer/api/api.js

+11-19
Original file line numberDiff line numberDiff line change
@@ -316,27 +316,19 @@ var common = require('../../../api/utils/common.js'),
316316
* @param {object} aggregation - aggregation object
317317
* */
318318
function aggregate(collection, aggregation) {
319-
aggregation.push({"$count": "total"});
320-
dbs[dbNameOnParam].collection(collection).aggregate(aggregation, function(err, total) {
321-
if (!err) {
322-
aggregation.splice(aggregation.length - 1, 1);
323-
var skip = parseInt(params.qstring.iDisplayStart || 0);
324-
aggregation.push({"$skip": skip});
325-
if (params.qstring.iDisplayLength) {
326-
aggregation.push({"$limit": parseInt(params.qstring.iDisplayLength)});
327-
}
328-
var totalRecords = total.length > 0 ? total[0].total : 0;
329-
dbs[dbNameOnParam].collection(collection).aggregate(aggregation, function(aggregationErr, result) {
330-
if (!aggregationErr) {
331-
common.returnOutput(params, {sEcho: params.qstring.sEcho, iTotalRecords: totalRecords, iTotalDisplayRecords: totalRecords, "aaData": result});
332-
}
333-
else {
334-
common.returnMessage(params, 500, aggregationErr);
335-
}
336-
});
319+
var skip = parseInt(params.qstring.iDisplayStart || 0);
320+
if (skip) {
321+
aggregation.push({"$skip": skip});
322+
}
323+
if (params.qstring.iDisplayLength) {
324+
aggregation.push({"$limit": parseInt(params.qstring.iDisplayLength)});
325+
}
326+
dbs[dbNameOnParam].collection(collection).aggregate(aggregation, function(aggregationErr, result) {
327+
if (!aggregationErr) {
328+
common.returnOutput(params, {sEcho: params.qstring.sEcho, iTotalRecords: result.length, iTotalDisplayRecords: result.length, "aaData": result});
337329
}
338330
else {
339-
common.returnMessage(params, 500, err);
331+
common.returnMessage(params, 500, aggregationErr);
340332
}
341333
});
342334
}

0 commit comments

Comments
 (0)