Skip to content

Commit 9f6bc30

Browse files
committed
Avoids mutating the provided query object.
1 parent d166bd4 commit 9f6bc30

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/__tests__/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,17 @@ describe('mongoose-cursor-pagination', function () {
110110
should.equal(results.items[4].value, 990)
111111
})
112112
})
113+
114+
it('does not modify the provided query object', function () {
115+
const query = {}
116+
117+
return mongoose.model('User').paginate(query, {
118+
key: 'value',
119+
sort: { value: -1 },
120+
endingBefore: 995
121+
})
122+
.then(() => {
123+
query.should.eql({})
124+
})
125+
})
113126
})

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function paginationPlugin (schema, pluginOptions) {
1212
}
1313

1414
schema.statics.paginate = function (query, options, callback) {
15-
query = query || {}
15+
query = query ? { ...query } : {}
1616
options = options || {}
1717
options.limit = +options.limit || defaultOptions.limit
1818
options = { ...defaultOptions, ...options }

0 commit comments

Comments
 (0)