Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Add hint support #129

Merged
merged 3 commits into from
Dec 17, 2018
Merged
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
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class Service {
q.collation(params.collation);
}

if (params.hint) {
q.hint(params.hint);
}

if (filters.$limit) {
q.limit(filters.$limit);
}
Expand Down
17 changes: 17 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('Feathers MongoDB Service', () => {
db.collection('people-customid').removeMany();
db.collection('people').removeMany();
db.collection('todos').removeMany();

db.collection('people').createIndex(
{ name: 1 },
{ partialFilterExpression: { team: 'blue' } }
);
})
);

Expand Down Expand Up @@ -239,6 +244,18 @@ describe('Feathers MongoDB Service', () => {
});
});
});

it('overrides default index selection using hint param if present', () => {
return peopleService
.create({ name: 'Indexed', team: 'blue' })
.then(r => {
return peopleService
.find({ query: { }, hint: { name: 1 } })
.then(r => {
expect(r).to.have.lengthOf(1);
});
});
});
});

describe('after fixing deprecation warning tests', () => {
Expand Down