MongoDB QL

Description

The MongoDB QL action executes one or more JSON instructions from this action’s configuration or from a file.

This action can be used to execute administrative instructions on a Mongo Database.

You can execute more than one JSON instruction.

Any JSON Instruction that can be used inside MongoDB’s runCommand(), can be executed by this action.

Options

Option Description

Action name

The name of the workflow action.

MongoDB Connection

The MongoDB connection to use.

Use external file

Enable this option to load the JSON instructions from a file.

Filename

The filename for the file with JSON instructions.

Use variable substitution

Enables variables to be used in the Script.

Fail on write errors

Make the action false when MongoDB reports write errors in its answer (writeErrors, writeConcernError or, for bulkWrite, nErrors), for example an insert with a duplicate _id. Leave it unchecked to accept a partial write, for example an unordered insert ("ordered": false) that skips duplicate keys: the write errors are then written to the log. Unchecked by default.

JSON

The JSON instructions to execute: one JSON document, or several in a JSON array ([ {…​}, {…​} ]). Semicolons at the end are allowed. Any other text after the document or the array is an error.

Examples

Single instruction

json
{"create":"hop_collection"}

Multiple instructions

json
[
    {"create":"hop_collection"},
    {"drop": "hop_collection" }
]

Result

What this action passes on to the next action. See Action results for how results travel through a workflow.

Result Value

True

Every instruction ran, with 0 errors. An instruction that returns documents, like find, is true too: the documents are not passed on.

False

The number of errors is 1. MongoDB Connection is empty or doesn’t exist, the server can’t be reached or refuses the login, Use external file is checked while Filename is empty or the file can’t be read, the JSON is empty or not valid, MongoDB refuses an instruction (for example an unknown command), or Fail on write errors is checked and MongoDB reports write errors or a write concern error in its answer (for example an insert with a duplicate _id). The instructions of an array run one after the other: the ones before the failing instruction stay done, the ones after it are not run.

Result files

Passed on unchanged.

Result rows

Passed on unchanged.

When an instruction has write errors, MongoDB still writes the documents before the failing one (and, for an unordered write, the documents after it). With Fail on write errors checked, the action is false and the instructions after it are not run.
Up to Hop 2.20, text after the first JSON document or array was ignored: in {"drop": "a"}, {"drop": "b"} only the first instruction ran. Since Hop 2.21 that text makes the action false, and none of the instructions run. Put several instructions in a JSON array.