Giter Club home page Giter Club logo

mongoose-ref-query's Introduction

MONGOOSE-REF-QUERY

Overview

  • Provides a mongoose model method that transforms http request objects into mongo query expressions. e.g. /monsters?name=joe&age={gt}20
  • Adds support for query expressions on referenced fields. e.g. /employee?manager.manager.name=herkules
  • It can check that the query matches the schema and if not throw an error ( disabled by default ).

Usage

Apply the plugin to any schema in the usual Mongoose fashion:

monsterSchema.plugin(mongooseRefQuery[, options]);

options

option type default description
throwErrors Boolean false will throw errors if the expression doesn't match the schema
debug Boolean false will print debug info (the final mongo query)

For the http interface

Monster.refQuery(req.query)()

returns a promise.

The refQuery call will throw an error if throwErrors is set in the options.

For the advanced mongo query interface

// .refQueryPrepare(expression[, config])
var trigger = Employee.refQueryPrepare({ "manager.manager.name" : "herkules" });
var promise = trigger();

The refQueryPrepare throws an error if set in the options, if not the invalid part of the expression will simply be ignored.

The config parameter is a query config object with the folowing options:

option type default description
ids_only Boolean false will return only the _id field
per_page Number 10 max number of records returned (0 means unlimited
page Number 1 page number
sort Object false sorting parameter e.g. { field_name : -1 }
populate Array:String [] list of populated fields

Http interface syntax

see http-interface

To run tests

See dev

License

MIT mit-license.org

mongoose-ref-query's People

Contributors

ajb avatar fghibellini avatar jedwood avatar sk91 avatar timosaikkonen avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

54sword

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.