lowdefy/packages/docs/operators/_mql.yaml
2021-01-27 18:02:28 +02:00

101 lines
3.3 KiB
YAML

# Copyright 2020-2021 Lowdefy, Inc
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_ref:
path: templates/operators.yaml.njk
transformer: templates/operatorsMethodTransformer.js
vars:
pageId: _mql
pageTitle: _mql
description: |
The `_mql` operator uses the [`mingo`](https://www.npmjs.com/package/mingo) package to evaluate MongoDB query language statements as an operator.
methods:
- name: aggregate
types: |
```
({on: object[], pipeline: object[]}): object[]
([on: object[], pipeline: object[]]): object[]
```
description: |
The `_mql.aggregate` method runs a MongoDB aggregation pipeline on an input array.
arguments: |
###### object
- `on: object[]`: The data array on which to run the pipeline. It should be an array of objects.
- `pipeline: object[]`: A MongoDB aggregation pipeline definition.
examples: |
###### Transform request results:
```yaml
_mql.aggregate:
pipeline:
- $match:
age:
$gte: 18
- $addFields:
averageScore:
$avg:
- $score1
- $score2
on:
_request: my_request
```
- name: expr
types: |
```
({on: object, expr: any}): any
([on: object, expr: any]): any
```
description: |
The `_mql.expr` method evaluates a MongoDB aggregation pipeline operator expression. This is any statement that could be written in a `$project` stage.
arguments: |
###### object
- `on: object`: An object to take as input for the expression.
- `expr: object`: A MongoDB aggregation expression.
examples: |
###### Calculate an average of three inputs:
```yaml
_mql.aggregate:
expr:
$avg:
- $input1
- $input2
- $input3
on:
_state: true
```
- name: test
types: |
```
({on: object, test: object}): boolean
([on: object, test: object]): boolean
```
description: |
The `_mql.test` method tests if a object matches a MongoDB filter/query expression.
arguments: |
###### object
- `on: object`: The object to be tested.
- `test: object`: A MongoDB filter/query expression.
examples: |
###### Test if a number input is greater than 100:
```yaml
_mql.test:
test:
number_input:
$gte: 18
on:
number_input:
_state: number_input
```