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

@sliit-foss/mongoose-filter-query

v7.0.2

Published

Middleware which implements a standardized format and maps an incoming http request's query params to a format which is supported by mongoose

Downloads

44

Readme

@sliit-foss/mongoose-filter-query

Middleware which implements a standardized format and maps an incoming http request's query params to a format which is supported by mongoose

Installation

# using npm
npm install @sliit-foss/mongoose-filter-query

# using yarn
yarn add @sliit-foss/mongoose-filter-query

Usage

const { default: mongooseFilterQuery } = require("@sliit-foss/mongoose-filter-query");

// or

import mongooseFilterQuery from "@sliit-foss/mongoose-filter-query";

.....
.....

// in your express app

app.use(mongooseFilterQuery);


// while invoking your database query

const data = await Model.find(req.query.filter).sort(req.query.sort)

console.log(data);

// rest of your code

Basic Usage Examples

"http://localhost:3000/api/users?filter[first_name]=eq(John)";
  • This will return all users with the first name John
"http://localhost:3000/api/users?filter[first_name]=ne(John)";
  • This will return all users with the first name not equal to John
"http://localhost:3000/api/users?filter[first_name]=reg(Jo)";
  • This will return all users with the first name matching the given regular expression
"http://localhost:3000/api/users?filter[age]=gt(20)";
  • This will return all users with the age greater than 20
"http://localhost:3000/api/users?filter[age]=gte(20)";
  • This will return all users with the age greater than or equal to 20
"http://localhost:3000/api/users?filter[age]=lt(20)";
  • This will return all users with the age less than 20
"http://localhost:3000/api/users?filter[age]=lte(20)";
  • This will return all users with the age less than or equal 20
"http://localhost:3000/api/users?filter[role]=in(staff,manager)";
  • This will return all users with a user role of either staff or manager
"http://localhost:3000/api/users?filter[role]=nin(staff,manager)";
  • This will return all users with a user role which is neither of staff and manager
"http://localhost:3000/api/users?filter[phone]=exists(true)";
  • This will return all users who have the phone number attribute in their database record
"http://localhost:3000/api/users?filter[phone]=exists(false)";
  • This will return all users who doesn't have the phone number attribute in their database record

Advanced Usage Examples

"http://localhost:3000/api/users?filter[first_name]=or(eq(John),eq(Eric),reg(Kat))";
  • This will return all users with a first name of John, Eric or matches the given regular expression
"http://localhost:3000/api/users?filter[or]=first_name=eq(John),last_name=eq(Eric)";
  • This will return all users with a first name of John or a last name of Eric
"http://localhost:3000/api/users?filter[age]=and(gt(20),lt(30))";
  • This will return all users with an age which is between 20 and 30
"http://localhost:3000/api/users?filter[and]=age=gt(20),first_name=eq(John)";
  • This will return all users with an age greater than 20 and a first name of John

Multiple Filters

  • Multiple filters can be chained together with the use of the & operator
"http://localhost:3000/api/users?filter[first_name]=eq(John)&filter[age]=gt(20)";
  • This will return all users with the first name John and an age greater than 20

Sorting Support

  • Filters could be used along with sorting
  • A value of 1 or asc for the sort parameter will sort the results in ascending order
  • A value of -1 or desc for the sort parameter will sort the results in descending order
"http://localhost:3000/api/users?filter[first_name]=eq(John)&sort[age]=1";
  • This will return all users with the first name John and sorted by age in ascending order
"http://localhost:3000/api/users?filter[first_name]=eq(John)&sort[age]=desc";
  • This will return all users with the first name John and sorted by age in descending order

Selection Support

"http://localhost:3000/api/users?filter[first_name]=eq(John)&select=first_name,last_name";
  • This will return all users with the first name John and only the first_name and last_name attributes will be returned
"http://localhost:3000/api/users?filter[first_name]=eq(John)&select=-first_name,-last_name";
  • This will return all users with the first name John and all attributes except the first_name and last_name attributes will be returned

Population Support

"http://localhost:3000/api/users?filter[first_name]=eq(John)&include=posts";
  • This will return all users with the first name John and the posts attribute will be populated
"http://localhost:3000/api/users?filter[first_name]=eq(John)&include=posts,comments";
  • This will return all users with the first name John and the posts and comments attributes will be populated