Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,29 @@ 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,
});

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 = {}) {
Expand Down
36 changes: 36 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const testSuite = adapterTests([
'.patch + id + query',
'.patch multiple',
'.patch multi query',
'.patch multi query changed',
'.patch + NotFound',
'.create',
'.create + $select',
Expand Down Expand Up @@ -188,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;

Expand Down