@@ -102,7 +102,9 @@ function aggregatePaginate(query, options, callback) {
102102 }
103103
104104 function constructPipelines ( ) {
105- let cleanedPipeline = pipeline . filter ( ( stage ) => stage !== PREPAGINATION_PLACEHOLDER ) ;
105+ let cleanedPipeline = pipeline . filter (
106+ ( stage ) => stage !== PREPAGINATION_PLACEHOLDER
107+ ) ;
106108
107109 const countPipeline = [ ...cleanedPipeline , { $count : "count" } ] ;
108110
@@ -122,7 +124,6 @@ function aggregatePaginate(query, options, callback) {
122124 return [ cleanedPipeline , countPipeline ] ;
123125 }
124126
125-
126127 let promise ;
127128 if ( options . useFacet && ! options . countQuery ) {
128129 let [ pipeline , countPipeline ] = constructPipelines ( ) ;
@@ -135,14 +136,15 @@ function aggregatePaginate(query, options, callback) {
135136 promise = q
136137 . facet ( {
137138 docs : pipeline ,
138- count : countPipeline
139+ count : countPipeline ,
139140 } )
140141 . then ( ( [ { docs, count } ] ) => [ docs , count ] ) ;
141142 } else {
143+ const [ pipeline , countPipeline ] = constructPipelines ( ) ;
142144
143- const [ pipeline ] = constructPipelines ( ) ;
144-
145- const countQuery = options . countQuery ? options . countQuery : this . aggregate ( pipeline ) ;
145+ const countQuery = options . countQuery
146+ ? options . countQuery
147+ : this . aggregate ( countPipeline ) ;
146148
147149 if ( allowDiskUse ) {
148150 countQuery . allowDiskUse ( true ) ;
@@ -236,4 +238,4 @@ function aggregatePaginate(query, options, callback) {
236238
237239module . exports = aggregatePaginate ;
238240
239- module . exports . PREPAGINATION_PLACEHOLDER = PREPAGINATION_PLACEHOLDER ;
241+ module . exports . PREPAGINATION_PLACEHOLDER = PREPAGINATION_PLACEHOLDER ;
0 commit comments