Skip to content

Commit

Permalink
Merge pull request #5 from limit-zero/dot-notated-fields
Browse files Browse the repository at this point in the history
Resolve issue with dot-notated/embedded fields
  • Loading branch information
zarathustra323 authored Jul 6, 2018
2 parents c5f03bc + b2ff98b commit 4c2ed48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ class Pagination {
* @return {Promise}
*/
getTotalCount() {
const run = () => this.Model
.find(this.criteria)
.comment(this.createComment('getTotalCount')).count();

const run = () => this.Model.count(this.criteria);
if (!this.promises.count) {
this.promises.count = run();
}
Expand Down Expand Up @@ -176,9 +173,9 @@ class Pagination {
filter._id = { [op]: doc.id };
} else {
doc = await this.findCursorModel(this.after, { [field]: 1 });
limits[op] = doc[field];
limits[op] = doc.get(field);
ors.push({
[field]: doc[field],
[field]: doc.get(field),
_id: { [op]: doc.id },
});
filter.$or = [{ [field]: limits }, ...ors];
Expand Down
3 changes: 2 additions & 1 deletion test/pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('pagination', function() {
});

beforeEach(function() {
sandbox.spy(Model, 'count');
sandbox.spy(Model, 'find');
sandbox.spy(Model, 'findOne');
sandbox.spy(Pagination.prototype, 'getEdges');
Expand Down Expand Up @@ -102,7 +103,7 @@ describe('pagination', function() {
const r1 = await paginated.getTotalCount();
const r2 = await paginated.getTotalCount();
expect(r1).to.equal(r2);
sinon.assert.calledOnce(Model.find);
sinon.assert.calledOnce(Model.count);
});
});

Expand Down

0 comments on commit 4c2ed48

Please sign in to comment.