Search…
Primer

Module Expressions

parse(expression)

Parse an expression.
This returns a JSON that contains a list of query parts, and methods for interacting with the query.
Arguments
    expression { Expression } Any valid expression.
1
const expressions = require('expressions')
2
return expressions.parse({
3
$toString: '$NOW'
4
})
Copied!
Returns
    { * } The ran expression.
1
{
2
"object": "result",
3
"data": {
4
"depth": 1,
5
"fullPath": "$toString",
6
"input": {
7
"$toString": "$NOW"
8
},
9
"path": "$toString",
10
}}
Copied!

run(expression, root)

This runs the command in the context of the current database.
Arguments
    expression { Expression } Any valid expression.
1
const expressions = require('expressions')
2
3
return expressions.run({
4
$toString: '$NOW'
5
})
Copied!
Returns
    { * } The ran expression.
1
{
2
"object": "result",
3
"data": "Wed Oct 07 2020 16:14:16 GMT+0000 (Coordinated Universal Time)"
4
}
Copied!

evaluate(expression, root)

This evaluates an expression, running the expression and returning a JSON that contains a list of query parts, and methods for interacting with the query. Arguments
    expression { Expression } Any valid expression.
1
const expressions = require('expressions')
2
3
return expressions.evaluate({
4
$toString: '$NOW'
5
})
Copied!
Returns
    { * } The ran expression.
1
{
2
"object": "result",
3
"data": {
4
"accessScope": {
5
"allow": 0,
6
"context": {
7
"object": ""
8
},
9
"grant": 0,
10
"instanceRoles": [],
11
"object": "ac",
12
"org": {
13
...}
14
}
15
}
16
}
Copied!

Pipelines

Pipeline aggregation allows for querying, aggregating, and transforming data in multiple stages in real-time through a single API request. While query arguments allow for making simple, single-stage queries through the API, pipelines allow for more complex searches, aggregations and transformations.

pipeline.parse(expression)

This returns a JSON that contains a list of query parts, and methods for interacting with the query.
Arguments
    expression { Expression } Any valid expression.
1
const expressions = require('expressions')
2
3
4
return expressions.parse({
5
$toString: '$NOW'
6
})
Copied!
Returns
    { * } The ran expression.
1
{
2
"object": "result",
3
"data": {
4
"depth": 1,
5
"fullPath": "$toString",
6
"input": {
7
"$toString": "$NOW"
8
},
9
"path": "$toString",
10
"type": "Expression$operator",
11
"value": {
12
"expression": {
13
...
14
}
15
}
16
}
17
}
Copied!

pipeline.run(expression, input)

This runs the command in the context of the current database.
Arguments
    expression { Expression } Any valid expression.
1
const expressions = require('expressions')
2
return expressions.pipeline.run([
3
{
4
$project: { $split: ['$ROOT', ' '] }
5
}
6
7
],
8
['This is a test', 'we are testing pipelines', 'Medable is cool']
9
).toArray()
Copied!
Returns
    { * } The ran expression.
1
{
2
"data": [
3
[
4
"This",
5
"is",
6
"a",
7
"test"
8
],
9
[
10
"We",
11
"are",
12
"testing",
13
"pipelines"
14
],
15
[
16
"Medable",
17
"is",
18
"cool"
19
]
20
],
21
"hasMore": false,
22
"object": "list"
23
}
Copied!
Arguments
    expression { Expression } Any valid expression.
    input { Array|Cursor = null } An array or cursor to serve as initial input.

pipeline.evaluate(expression, input)

This evaluates an expression, running the expression and returning a JSON that contains a list of query parts, and methods for interacting with the query.
Arguments
    expression { Expression } Any valid expression.
1
const expressions = require('expressions')
2
return expressions.pipeline.evaluate([
3
{
4
$project: { $split: ['$ROOT', ' '] }
5
}
6
7
],
8
['This is a message', 'Pipelines are being tested', 'Sky is blue']
9
)
Copied!
Returns
    { * } The evaluated expression.
1
{
2
"object": "result",
3
"data": {
4
"accessScope": {
5
"allow": 0,
6
"context": {
7
"object": ""
8
},
9
"grant": 0,
10
}}}
Copied!
Last modified 1mo ago