npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mongoose-hint

v0.3.0

Published

Generate hints for Mongoose queries on the fly

Readme

mongoose-hint

Generate hints on the fly for every Mongoose query.

node Twitter

Note:

  • Minimum Node: v4.0.0
  • Minimum Mongoose: v4.0

Example

const mongoose = require('mongoose');
const hintPlugin = require('mongoose-hint');

// Mongoose schema
const Employee = mongoose.Schema({
  firstName: String,
  lastName: String,
  badgeNum: Number,
  locationId: String,
  teamId: String,
  type: {
    type: String,
    enum: [
      'ENG',
      'MGMT',
    ],
  },
});

// Indexes for schema
const TEAM_INDEX = {
  teamId: 1,
};

const LOCATION_TEAM_INDEX = {
  locationId: 1,
  teamId: -1,
};

const TEAM_TYPE_INDEX = {
  teamId: 1,
  type: 1,
};

Employee.index(TEAM_INDEX);
Employee.index(LOCATION_TEAM_INDEX);
Employee.index(TEAM_TYPE_INDEX);

// set the plugin with the hints to use, in order of priority
Employee.plugin(hintPlugin.find, [
  LOCATION_TEAM_INDEX,
  TEAM_TYPE_INDEX,
  TEAM_INDEX,
]);

// Queries
Employee.find({
  firstName: 'Kevin',
  teamId: 13,
  type: 'MGMT',
});
// applies TEAM_TYPE_INDEX hint

Employee.find({
  firstName: 'Kevin',
  teamId: 13,
});
// applies TEAM_INDEX hint

Employee.find({
  firstName: 'Kevin',
  teamId: 13,
  type: 'MGMT',
  locationId: '02446',
});
// applies LOCATION_TEAM_INDEX hint

Employee.find({
  firstName: 'Kevin',
  teamId: 13,
  type: 'MGMT',
  locationId: '02446',
}).hint({
  teamId: 1
});
// applies the given hint

Details

Uses ikat under the hood for pattern matching. Uses Mongoose middleware to apply hints to queries if a hint has not already been defined.

Pass in the hints in the array in order of priority - the first hint that matches the query will be used.

Supports find queries and update queries. require('mongoose-hint') exposes both find and update plugins. You can use either one, or both.

Tests

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

Linting

Linting can be run via the npm run lint command. All code must pass the code quality checks provided by eslint.

Contributing

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!