Skip to content

Commit

Permalink
Merge pull request #187 from sliit-foss/perf/aggregate-paginate-plugin
Browse files Browse the repository at this point in the history
Perf/aggregate paginate plugin
  • Loading branch information
Akalanka47000 authored Jul 5, 2024
2 parents b730979 + 42d5827 commit 72a5e8f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/mongoose-aggregate-paginate-v2/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function aggregatePaginate(query, options, callback) {
const allowDiskUse = options.allowDiskUse || false;
const isPaginationEnabled = options.pagination === false ? false : true;

const q = this.aggregate();
let q = this.aggregate();

if (allowDiskUse) {
q.allowDiskUse(true);
Expand Down Expand Up @@ -120,7 +120,13 @@ export function aggregatePaginate(query, options, callback) {
let promise;

if (options.useFacet && !options.countQuery) {
const [pipeline, countPipeline] = constructPipelines();
let [pipeline, countPipeline] = constructPipelines();
const match = pipeline[0]?.$match;
if (match) {
pipeline.shift();
countPipeline.shift();
q = q.match(match);
}
promise = q
.facet({
docs: pipeline,
Expand Down

0 comments on commit 72a5e8f

Please sign in to comment.