0.3.1 • Published 9 years ago

mongoose-ref-query v0.3.1

Weekly downloads
28
License
-
Repository
-
Last release
9 years ago

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

optiontypedefaultdescription
throwErrorsBooleanfalsewill throw errors if the expression doesn't match the schema
debugBooleanfalsewill 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:

optiontypedefaultdescription
ids_onlyBooleanfalsewill return only the _id field
per_pageNumber10max number of records returned (0 means unlimited
pageNumber1page number
sortObjectfalsesorting parameter e.g. { field_name : -1 }
populateArray:String[]list of populated fields

Http interface syntax

see http-interface

To run tests

See dev

License

MIT mit-license.org

0.3.1

9 years ago

0.3.0

9 years ago

0.2.2

9 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago