Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qs2mongo

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qs2mongo

qs2mongo

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
109
increased by4.81%
Maintainers
1
Weekly downloads
 
Created
Source

qs2mongo

NPM version

Querystring to mongo mapper

Builds filters, projections and options for mongoose queries

  • In your querystring:
    • attributes=comma,separated,fields maps to projection { comma: 1, separated: 1, fields: 1 }
    • limit=1,offset=2 maps to options { limit: 1, offset: 2 }
    • Sorts
      • Ascending: sort=field maps to options { sort: { field: 1 } }
      • Descending: sort=-field maps to options { sort: { field: -1 } }
    • Any other key maps to a mongo filter. Available options are:
      • strict: key=value is { key: value }
      • not strict: key=value is { key: /value/gi }
      • or: key,anotherKey=value is $or: [{key:value}, {anotherKey:anotherValue}]
      • unary operators: key__gt=value is {key: $gt: "value"}
Basic usage
Qs2Mongo = require ("qs2mongo")
qs2mongo = new Qs2Mongo()
#... 
anEndpoint: (req, res): =>
  { filters, projection, options } = qs2mongo.parse req
Usage as middleware
Qs2Mongo = require ("qs2mongo")
config = ...
qs2mongo = new Qs2Mongo config
#... 
router.use qs2mongo.middleware

#... 
anEndpoint: (req, res): =>
  { filters, projection, options } = req.mongo

Config
  {
    defaultSort, 
    idField = "id", 
    multigetIdField = "_id", 
    filterableBooleans = [], 
    filterableDates = [], 
    omitableProperties = Qs2Mongo.defaultOmitableProperties
  }
Specify types of querystring keys
qs2mongo = new Qs2Mongo
  filterableBooleans: ["aBooleanField","anotherBooleanField"]
  filterableDates: ["aDateField","anotherDateField"]

FAQs

Package last updated on 21 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc