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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mangomodel-search

v0.3.0

Published

A search mixin for mangomodel

Downloads

11

Readme

MangoModel Search

This is a mix in for Mango Model to assist searching mongo collections.

Initialisation

var MangoModel = require('mangomodel');
var MangoModelSearch = require('mangomodel-search');

// Create your model
var Ants = MangoModel.create('ants');

// Mix in the search method
Ants.methods(MangoModelSearch());

// or set some defaults
Ants.methods(MangoModelSearch({ $limit: 100, $sort: 'friends,desc' }));

Options

  • $limit - Limit the number of results returned from a search. Default is 20

  • $sort - Specify the property and method to sort by. Syntax is property name followed by an optional comma and sort method. eg. "age,desc". Default is "created_at,desc"

  • $from - A data point to return results only after and including from that point. The property this data point refers to is determined by the sort option. eg. By defaut sort is sorting the created_at property in descending order. Therefore If you specify a from option it's value must be date and the query will return all results created less than and including the date provided in the from option.

  • $until - Similar to from but in reverse. Using the created_at example again. If a until is specified instead of from, it will return all results upto and including the value provided in the until option.

Examples

// no options
Ants.search(function(err, ants) {
  // returns a list of ants with the default limit and sort applied
});

// With options
Ants.search({ $limit: 50 }, function(err, ants) {
  // returns 50 ants sorted by default sort
});

// Using $from with sort in descending order. Assume the column friends is an integer
Ants.search({ $sort: 'friends,desc', $from: 30 }, function(err, ants) {
  // returns all ants with 30 friends or less. Ants with the most friends will be returned first
});

// Using $from with sort in ascending order. Assume the column friends is an integer
Ants.search({ $sort: 'friends,asc', $from: 30 }, function(err, ants) {
  // returns all ants with 30 friends or more. Ants with the least friends will be returned first
});

// Using $until with sort in descending order. Assume the column friends is an integer
Ants.search({ $sort: 'friends,desc', $until: 30 }, function(err, ants) {
  // returns all ants with 30 friends or more. Ants with the most friends will be returned first
});

// Using $until with sort in ascending order. Assume the column friends is an integer
Ants.search({ $sort: 'friends,asc', $until: 30 }, function(err, ants) {
  // returns all ants with 30 friends or less. Ants with the least friends will be returned first
});