@@ -316,27 +316,19 @@ var common = require('../../../api/utils/common.js'),
316
316
* @param {object } aggregation - aggregation object
317
317
* */
318
318
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 } ) ;
337
329
}
338
330
else {
339
- common . returnMessage ( params , 500 , err ) ;
331
+ common . returnMessage ( params , 500 , aggregationErr ) ;
340
332
}
341
333
} ) ;
342
334
}
0 commit comments