# mongoose-ref-query

> http queries & queries on reference properties

Latest version **0.3.1** (published 2015-05-17) · 0 weekly downloads

## Install

```sh
npm install mongoose-ref-query
pnpm add mongoose-ref-query
yarn add mongoose-ref-query
bun add mongoose-ref-query
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2015-05-17 |
| First published | 2014-08-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Filippo Ghibellini |
| Maintainers | fghibellini |
| Keywords | API, ref, mongoose, search, parameters |

## Links

- npm: https://www.npmjs.com/package/mongoose-ref-query
- Homepage: http://github.com/fghibellini/mongoose-api-query
- npm.io page: https://npm.io/package/mongoose-ref-query

## Dependencies (1)

- [q](https://npm.io/package/q.md) ^1.0.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 0.3.1 (latest) — 2015-05-17
- 0.3.0 — 2015-05-07
- 0.2.2 — 2014-12-01
- 0.2.1 — 2014-11-09
- 0.2.0 — 2014-11-09
- 0.1.1 — 2014-09-11
- 0.1.0 — 2014-08-25

## README

# 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](docs/http-interface.md)

## To run tests

See [dev](docs/dev.md)

## License

MIT [mit-license.org](http://mit-license.org/)

---
_Source: https://npm.io/package/mongoose-ref-query · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
