Skip to content

Commit

Permalink
Merge remote-tracking branch 'aravindc/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 authored Jul 23, 2024
2 parents 4a25bdb + d4ecf92 commit eb09c22
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ typings/
# next.js build output
.next

dist
dist
.idea/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.1.1

[2024-07-05]

- Added match stage before facet to improve performance.

## v1.1.0

[2024-06-24]
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoose-aggregate-paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ function aggregatePaginate(query, options, callback) {
})
.then(([{ docs, count }]) => [docs, count]);
} else {
const [pipeline] = constructPipelines();
const [pipeline, countPipeline] = constructPipelines();

const countQuery = options.countQuery
? options.countQuery
: this.aggregate(pipeline);
: this.aggregate(countPipeline);

if (allowDiskUse) {
countQuery.allowDiskUse(true);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"pretest": "npm run prepare",
"test": "mocha tests/*.js -R spec --ui bdd --timeout 5000",
"prepare": "babel lib -d dist",
"lint": "./node_modules/.bin/eslint \"tests\" \"lib\" \".eslintrc.js\" --fix",
"prettier": "./node_modules/.bin/prettier --write \"{lib,tests}/**/*.js\" \"*.md\"",
"lint": "eslint \"tests\" \"lib\" \".eslintrc.js\" --fix",
"prettier": "prettier --write \"{lib,tests}/**/*.js\" \"*.md\"",
"prepublishOnly": "npm run test"
},
"husky": {
Expand Down
Binary file modified static/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,45 @@ describe("mongoose-paginate", function () {
expect(result.pageCount).to.equal(5);
});
});

it("without facet", () => {
// part of the reason for this test is due to working the usage of $search in the aggregation pipeline which is
// not supported with facets. The building of a query without facets previously had a bug that meant the pagination
// details were based on a single page of results, rather than the full count of results from a pipeline. While
// this is a basic test it verifies the pagination still returns the correct result while not using facets.
var aggregate = Book.aggregate([
{
$match: {
title: {
$in: [/Book/i],
},
},
},
{
$sort: {
date: 1,
},
},
]);
var options = {
limit: 10,
page: 2,
useFacet: false,
};
return Book.aggregatePaginate(aggregate, options).then((result) => {
expect(result.docs).to.have.length(10);
expect(result.docs[0].title).to.equal("Book #41");
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(10);
expect(result.page).to.equal(2);
expect(result.pagingCounter).to.equal(41);
expect(result.hasPrevPage).to.equal(true);
expect(result.hasNextPage).to.equal(true);
expect(result.prevPage).to.equal(1);
expect(result.nextPage).to.equal(3);
expect(result.totalPages).to.equal(10);
});
});
});

describe("sorting", function () {
Expand Down

0 comments on commit eb09c22

Please sign in to comment.