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

mongomatch

v0.1.0

Published

Mongo-like object queries in Javascript

Readme

mongomatch

mongomatch is a Javascript utility that allows for Mongo-like querying on Javascript objects. With it, you can create underscore/lodash's findWhere on steroids:

// this is like underscore/lodash's _.findWhere, but does deep object
// querying, with support for matching using regex, arrays, functions,
// and (some of) mongo's special operators. see below for supported queries
var findWhereOnSteroids = function(list, query) {
  return list.filter(mongomatch.bind(null, query));
};

A contrived example:

// An array of information about a bunch of siblings
var childrenRecords = [{
  name: 'Charles',
  age: 12,
  favorites: ['ice cream', 'candy', 'pokemon'],
  favoriteParent: {
    name: 'Mary',
    age: 29
  }
}, {
  name: 'May',
  age: 14,
  favorites: ['Javascript', 'programming'],
  favoriteParent: {
    name: 'Mary',
    age: 29
  }
}, {
  name: 'Barry',
  age: 18,
  favorites: ['ice cream', 'programming'],
  favoriteParent: {
    name: 'John',
    age: 32
  }
}];

// query for every child with a favorite parent whose
// name ends with the letter "y"
var query = {
  favoriteParent: {
    name: /y$/
  }
};

var results = findWhereOnSteroids(childrenRecords, query);
console.log(results.length); // 2
console.log(results); // [{ name: 'Charles', ... }, { name: 'May', ... }]

Function Signature

mongomatch is simply a predicate function with the following signature:

mongomatch(query, record)

where query is a Mongo-like query object and record is a Javascript object. Calling mongomatch returns a boolean indicating whether the record matches the query.

Supported Queries

Exact Match

// matches "May"
// simply matches a child with name field equal to "May"
var query = {
  name: 'May'
};

Regex

// matches "May" and "Barry"
// matches a child with name ending in "y"
var query = {
  name: /y$/
};

Exact match on an array

// matches "May"
// note that "Javascript" must be the first element, and "programming" must be
// the second element for it to be a match
var query = {
  favorites: ['Javascript', 'programming']
};

Match an array element

// matches "Charles" and "Barry"
// this simply checks if the element "ice cream" is in the `favorites` array
var query = {
  favorites: 'ice cream'
};

Function

// matches "Barry"
// this matches any child whose favorite parent has an age that is even
var query = {
  favoriteParent: {
    age: function(age) {
      return age % 2 === 0;
    }
  }
};

Special mongo operators ($gt, $gte, $lt, $lte, $in)

// matches "May" and "Barry"
// this matches any child whose age is greater than 12 (not inclusive)
var query = {
  age: { $gt: 12 }
};

// matches "May"
// this matches any child whose age is greater than or equal to 14
// AND less than 18
var query = {
  age: { $gte: 14, $lt: 18 }
};

// matches "Charles"
// this matches a child whose favorites include "ice cream" and "pokemon"
// order does NOT matter within the array
var query = {
  favorites: { $in: ['pokemon', 'ice cream'] }
};

Project Goals

The goal of this project is not to reach feature parity with MongoDB's rich querying language. Some of Mongo's more commonly used special operators are included as useful shortcuts when doing deep object pattern matching. More complex cases involving $and or $or can be more succinctly expressed as function queries.