diff --git a/src/index.ts b/src/index.ts index f7a6c77..8fb596e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,7 +78,7 @@ export default function (schema: Schema, pluginOptions?: IPluginOptions) { options.limit = useDefaultLimit ? defaultLimit : options.limit; // Apply pagination to the pipeline - const paginatedPipeline = [...generateAggregatePipeline(options), ...pipeline, { $sort: sort as any }]; + const paginatedPipeline = [...pipeline, ...generateAggregatePipeline(options), { $sort: sort as any }]; if (!unlimited) { paginatedPipeline.push({ $limit: options.limit + 1 });