MongoDB Collection

Reads or writes documents in a MongoDB collection, depending on operation.

Configuration

- mongodb_collection:
    name: read_customers
    operation: read
    credentials_path: /etc/mongodb/credentials.json
    db_name: sales
    collection_name: customers
    filter:
      status: "active"

Fields

FieldTypeDefaultDescription
namestringrequiredTask name.
operationstringrequiredread or write.
credentials_pathstringPath to MongoDB credentials file. Omit to connect to localhost:27017 without authentication. See Credentials.
db_namestringrequiredDatabase name.
collection_namestringrequiredCollection name.
filtermapKey-value pairs to filter documents. Only used by operation: read.
depends_onlistUpstream task names.
retryobjectRetry configuration.

Examples

Read with a filter:

- mongodb_collection:
    name: read_customers
    operation: read
    credentials_path: /etc/mongodb/credentials.json
    db_name: sales
    collection_name: customers
    filter:
      status: "active"

Write the incoming event as a document:

- mongodb_collection:
    name: write_customer
    operation: write
    credentials_path: /etc/mongodb/credentials.json
    db_name: sales
    collection_name: customers

See Credentials for the credentials file format.

Output

FormatCrateDescription
JSONmongodbread: each matching document, converted to JSON, event.id set to the document’s _id. write: the insert result with the generated ObjectId, event.id set to the inserted document’s _id.