diff --git a/src/utils/feathers-mongoose/service.js b/src/utils/feathers-mongoose/service.js index 04522a0756f..f2c1a860394 100644 --- a/src/utils/feathers-mongoose/service.js +++ b/src/utils/feathers-mongoose/service.js @@ -462,6 +462,17 @@ class Service extends AdapterBase { filterQuery(params) { const options = this.getOptions(params); + + // $limit=false - should return all records with structure as with pagination (total, limit, skip, data) + const paginateNoLimit = { + default: undefined, + max: undefined, + }; + if (params.query && (params.query.$limit === 'false' || params.query.$limit === false)) { + options.paginate = paginateNoLimit; + params.query.$limit = undefined; + } + const { $select, $sort, $limit: _limit, $skip = 0, $populate, ...query } = params.query || {}; const $limit = getLimit(_limit, options.paginate); diff --git a/test/services/school/index.test.js b/test/services/school/index.test.js index 93c8bebea67..f1817289b53 100644 --- a/test/services/school/index.test.js +++ b/test/services/school/index.test.js @@ -575,6 +575,42 @@ describe('school service', () => { }); }); +describe('find schools', () => { + let app; + let server; + let schoolsService; + + before(async () => { + app = await appPromise(); + server = await app.listen(); + schoolsService = app.service('schools'); + }); + + after(async () => { + await server.close(); + }); + + afterEach(async () => { + await testObjects.cleanup(); + }); + + beforeEach('set data samples', async () => { + await testObjects.createTestSchool({}); + await testObjects.createTestSchool({}); + await testObjects.createTestSchool({}); + }); + + it('find with pagination and limit', async () => { + const result = await schoolsService.find({ query: { $limit: 2 } }); + expect(result.data.length).to.be.equal(2); + }); + + it('find should return all schools when $limit = false', async () => { + const result = await schoolsService.find({ query: { $limit: false } }); + expect(result.data.length).to.be.equal(result.total); + }); +}); + describe('years service', () => { let app; let server;