From f7bb6b477bf78d33faa851434c79effed3af11af Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 17:52:01 -0500 Subject: [PATCH 1/4] Use idList strategy --- lib/index.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9b818e2..582ecee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -212,15 +212,30 @@ class Service extends AdapterService { query = Object.assign(query, { collation: params.collation }); } - const findParams = Object.assign({}, params, { - paginate: false - }); const remapModifier = this._remapModifiers(this._normalizeId(id, data)); - return this.Model.updateMany(query, remapModifier, options) - .then(() => this._findOrGet(id, findParams)) - .then(select(params, this.id)) - .catch(errorHandler); + const idParams = Object.assign({}, params, { + paginate: false, + query: Object.assign({}, query, { $select: [this.id] }) + }); + + const ids = this._findOrGet(id, idParams) + .then(result => { + const items = Array.isArray(result) ? result : [result]; + return items.map(item => item[this.id]); + }); + + return ids.then(idList => { + const findParams = Object.assign({}, params, { + paginate: false, + query: { [this.id]: { $in: idList } } + }); + + return this.Model.updateMany(query, remapModifier, options) + .then(() => this._findOrGet(id, findParams)) + .then(select(params, this.id)) + .catch(errorHandler); + }); } _update (id, data, params = {}) { From 5a84ee9c4d1913fdbbf9a484e61e9fc93b0de75b Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 18:34:57 -0500 Subject: [PATCH 2/4] Remove $select --- lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 582ecee..7537015 100644 --- a/lib/index.js +++ b/lib/index.js @@ -216,7 +216,6 @@ class Service extends AdapterService { const idParams = Object.assign({}, params, { paginate: false, - query: Object.assign({}, query, { $select: [this.id] }) }); const ids = this._findOrGet(id, idParams) From 07e9f795f619bf1d254ff8d3368fdf3b55f4ae1a Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 19:22:05 -0500 Subject: [PATCH 3/4] Add .patch multi query changed test --- test/index.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/index.test.js b/test/index.test.js index 15cd6b6..c96db98 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -33,6 +33,7 @@ const testSuite = adapterTests([ '.patch + id + query', '.patch multiple', '.patch multi query', + '.patch multi query changed', '.patch + NotFound', '.create', '.create + $select', From b5b8e782bce07415858f8a6c8800d6eb25d607fd Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 19:35:16 -0500 Subject: [PATCH 4/4] Leave commented test --- test/index.test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index c96db98..37d9762 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -189,6 +189,41 @@ describe('Feathers MongoDB Service', () => { }); }); + // describe('.patch multi query changed', () => { + // let peopleService, people; + + // beforeEach(async () => { + // peopleService = app.service('/people'); + // peopleService.options.multi = true; + // people = await Promise.all([ + // peopleService.create({ name: 'AAA' }), + // peopleService.create({ name: 'aaa' }), + // peopleService.create({ name: 'ccc' }) + // ]); + // }); + + // afterEach(async () => { + // peopleService.options.multi = false; + // await Promise.all([ + // peopleService.remove(people[0]._id), + // peopleService.remove(people[1]._id), + // peopleService.remove(people[2]._id) + // ]).catch(() => {}); + // }); + + // it('Returns correct result when queried props are patched',async () => { + // const result = await peopleService.patch(null, { name: 'patched' }, { + // query: { name: { $gt: 'AAA' } } + // }); + + // expect(result).to.be.an('array'); + // expect(result).to.have.lengthOf(2); + // result.forEach(person => { + // expect(person.name).to.equal('patched'); + // }); + // }); + // }); + describe('Special collation param', () => { let peopleService, people;