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.

const expressions = require('expressions')
return expressions.parse({
    $toString: '$$NOW'
})

Returns

  • { * } The ran expression.

{
    "object": "result",
    "data": {
        "depth": 1,
        "fullPath": "$toString",
        "input": {
            "$toString": "$$NOW"
        },
        "path": "$toString",
      }}

run(expression, root)

This runs the command in the context of the current database.

Arguments

  • expression { Expression } Any valid expression.

const expressions = require('expressions')

return expressions.run({
    $toString: '$$NOW'
})

Returns

  • { * } The ran expression.

{
    "object": "result",
    "data": "Wed Oct 07 2020 16:14:16 GMT+0000 (Coordinated Universal Time)"
}

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.

const expressions = require('expressions')

return expressions.evaluate({
    $toString: '$$NOW'
})

Returns

  • { * } The ran expression.

{
    "object": "result",
    "data": {
        "accessScope": {
            "allow": 0,
            "context": {
                "object": ""
            },
            "grant": 0,
            "instanceRoles": [],
            "object": "ac",
            "org": {
        ...}
      }
    }
  }

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.

const expressions = require('expressions')


return expressions.parse({
    $toString: '$$NOW'
})

Returns

  • { * } The ran expression.

{
    "object": "result",
    "data": {
        "depth": 1,
        "fullPath": "$toString",
        "input": {
            "$toString": "$$NOW"
        },
        "path": "$toString",
        "type": "Expression$operator",
        "value": {
            "expression": {
              ...
            }
          }
        }
      }

pipeline.run(expression, input)

This runs the command in the context of the current database.

Arguments

  • expression { Expression } Any valid expression.

const expressions = require('expressions')
return expressions.pipeline.run([
        {
          $project: { $split: ['$$ROOT', ' '] }
        }

      ],
      ['This is a test', 'we are testing pipelines', 'Medable is cool']
      ).toArray()

Returns

  • { * } The ran expression.

{
    "data": [
        [
            "This",
            "is",
            "a",
            "test"
        ],
        [
            "We",
            "are",
            "testing",
            "pipelines"
        ],
        [
            "Medable",
            "is",
            "cool"
        ]
    ],
    "hasMore": false,
    "object": "list"
}

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.

const expressions = require('expressions')
return expressions.pipeline.evaluate([
        {
          $project: { $split: ['$$ROOT', ' '] }
        }

      ],
      ['This is a message', 'Pipelines are being tested', 'Sky is blue']
      )

Returns

  • { * } The evaluated expression.

{
    "object": "result",
    "data": {
        "accessScope": {
            "allow": 0,
            "context": {
                "object": ""
            },
            "grant": 0,
          }}}

Last updated