# @quenk/facets-mongodb

> search-filters compiler for mongodb targets.

Latest version **1.0.2** (published 2020-01-24) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @quenk/facets-mongodb
pnpm add @quenk/facets-mongodb
yarn add @quenk/facets-mongodb
bun add @quenk/facets-mongodb
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-01-24 |
| First published | 2019-04-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Quenk Technologies |
| Maintainers | metasansana |

## Links

- npm: https://www.npmjs.com/package/@quenk/facets-mongodb
- npm.io page: https://npm.io/package/@quenk/facets-mongodb

## Dependencies (2)

- [@quenk/noni](https://npm.io/package/@quenk/noni.md) ^1.36.0
- [@quenk/search-filters](https://npm.io/package/@quenk/search-filters.md) ^2.3.2

## Recent versions

- 1.0.2 (latest) — 2020-01-24
- 1.0.1 — 2020-01-24
- 0.3.6 — 2020-01-13
- 0.3.5 — 2020-01-13
- 0.3.4 — 2020-01-02
- 0.3.3 — 2019-11-11
- 0.3.2 — 2019-08-20
- 0.3.1 — 2019-08-20
- 0.3.0 — 2019-04-11
- 0.2.0 — 2019-04-11
- 0.1.0 — 2019-04-10

## README

# Search Filters MongoDB

search-filters compiler for mongodb targets

## Installation

```sh
npm install --save @quenk/search-filters-mongodb
```

## Usage

This module provides a [@quenk/search-filters][1] compiler for generating
mongodb [query operators][2]. It targets the [Node.js Driver API][3] particularly
the `Collection#find` method.

To compile a source string, create an instance of `MongoDBFilterCompiler`
and apply the `compile()` method giving it an [EnabledPolicies][4] and 
a valid source string.

### Available Policies

This module ships with the following [Available Policies][5] :

| Policy Name    | Type         | Operators      | Notes                       |
|----------------|--------------|--------------- |-----------------------------|
| number         | number       | = < > >= <= != |                             |
| boolean        | boolean      | = < > >= <= != |                             |
| string         | string       | = !=           | Tests equality.             |
| match          | string       | =              | Converts value to regex.    |
| matchci        | string       | =              | Case-insensitive "match".   |
| date           | date         | = < > >= <= != | Actual value instanceof Date|    

You can specify a policy name instead of a definition in `EnabledPolicies`
and it will be subsitituted at compile time. 
Consult the [search-filters][1] docs for more information.

You can add additional `AvailablePolicies` by overriding the `policies`
argument of the `MongoDBFilterCompiler`.

### Example

```typecript
import {Value} from '@quenk/noni/lib/data/jsonx';
import {MongoDBFilterCompiler} from '@quenk/search-filters-mongodb';
import {FilterTerm} from '@quenk/search-filters-mongodb/lib/term';

const policies = {

 name: 'matchci',

 age: 'number'

 status: {

   type: 'number',
   operators: ['='],
   term: (field:string, op:string, value:Value ) => 
       new FilterTerm(field, op, value)

 }

}

const qry = '(name:"sana" or name:="Murr") and age:>20 and status:1';

let mfc = new MongoDBFilterCompiler();

let eResult = mfc.compile(qry);

/* Logs the below or throws if an error occured. 
  {"$and":
    [
       {
         "$or":[
            {"name":{"$regex":"sana", $options:"i"}},
            {"name":{"$regex":"Murr", $options:"i"}}
          ]
        },
        {"age":{"$gt":20}},
        {"status":{"$eq":1}}
    ]
   }
*/
console.log(eResult.takeRight());

```

## License

Apache 2.0 (SEE LICENSE) file. (c) Quenk Technologies Limited.

[1]: https://quenktechnologies.github.io/search-filters
[2]: https://docs.mongodb.com/manual/reference/operator/query/
[3]: https://mongodb.github.io/node-mongodb-native/3.5/api/
[4]: https://quenktechnologies.github.io/search-filters/interfaces/_compile_policy_.enabledpolicies.html
[5]: https://quenktechnologies.github.io/search-filters/interfaces/_compile_policy_.availablepolicies.html

---
_Source: https://npm.io/package/@quenk/facets-mongodb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
