Generate hints on the fly for every Mongoose query.
- Minimum Node: v4.0.0
- Minimum Mongoose: v4.0
const mongoose = ;const hintPlugin = ;// Mongoose schemaconst Employee = mongoose;// Indexes for schemaconst TEAM_INDEX =teamId: 1;const LOCATION_TEAM_INDEX =locationId: 1teamId: -1;const TEAM_TYPE_INDEX =teamId: 1type: 1;EmployeeindexTEAM_INDEX;EmployeeindexLOCATION_TEAM_INDEX;EmployeeindexTEAM_TYPE_INDEX;// set the plugin with the hints to use, in order of priorityEmployee;// QueriesEmployee;// applies TEAM_TYPE_INDEX hintEmployee;// applies TEAM_INDEX hintEmployee;// applies LOCATION_TEAM_INDEX hintEmployee;// applies the given hint
Pass in the hints in the array in order of priority - the first hint that matches the query will be used.
find queries and
require('mongoose-hint') exposes both
update plugins. You can use either one, or both.
Tests can be run via the
npm test command. We aim to write tests for all supported behaviors.
Note: To run tests, you will need to have a Mongo instance to connect to. By default we use the
ikat_mongoose_hint_plugin_test_db database locally, but you can pick which database you'd like to run tests against with the
TEST_DB environment variable like so:
TEST_DB=mongodb://127.0.0.1/test_db npm test
Contributions are always welcome! This may come in the form of constructive criticism via GitHub issues, or direct PRs. Contributions will be required to pass all tests and must adhere to the guidelines set forth by the eslint style guide. This includes source files & test files.
Have suggestions? Add them via a GitHub issue!