Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

Sources

Connect DocumentDB as a source

Create a DocumentDB service account, enable change streams, and connect your cluster to an Artie pipeline through an SSH tunnel or AWS PrivateLink.

Prerequisites

  • An SSH tunnel or AWS PrivateLink into your cluster’s VPC. DocumentDB clusters aren’t publicly reachable, so Artie can’t connect directly.
  • The cluster endpoint and port. The default port is 27017.
  • The name of the database to replicate.

To find the cluster endpoint, open the AWS console, select the DocumentDB cluster, and go to the Configuration tab.

DocumentDB cluster endpoint

Set up DocumentDB

These steps cover the Source section of pipeline setup. If you reuse a DocumentDB source from another pipeline, setup skips Network access and Prepare source.

  1. Choose DocumentDB

    On Choose source, select DocumentDB.

  2. Choose how Artie reaches the cluster

    On Network access, select SSH tunnel or PrivateLink, then select Continue. DocumentDB has no Allowlist Artie IPs card, because Artie can’t reach the cluster directly.

    When you link a PrivateLink connection, Artie turns off Use TLS. Removing the PrivateLink turns it back on.

    DocumentDB clusters require TLS by default, so turn Use TLS back on before you verify the connection. Artie doesn’t check the cluster’s certificate, so the PrivateLink endpoint’s hostname doesn’t cause a mismatch.

  3. Create a service account

    Artie reads change stream events as this user. Run this script against your cluster:

    setup.js
    // Creating a service account for Artie to subscribe to change stream
    db.createUser({user: "artie", pwd: "YOUR_PASSWORD", roles: ["read"]});
    // Grants access to DocumentDB change streams
    use admin;
    db.grantRolesToUser("artie", [
      { role: "readAnyDatabase", db: "admin" }
    ]);

    Replace YOUR_PASSWORD with the user’s password. Prepare source shows this script with the example password changeme.

  4. Enable change streams

    Artie opens one change stream on the whole database you replicate, so enable change streams on that database or on every database. Run one of these commands:

    // Enable change streams for all collections in database "DATABASE_NAME"
    db.adminCommand({
        modifyChangeStreams: 1,
        database: "DATABASE_NAME",
        collection: "",
        enable: true
    });

    Replace DATABASE_NAME with the database you replicate. Prepare source may show the example name bar, because you enter the database name later, on Connect and verify. Its collection-only command isn’t enough, because Artie watches the whole database.

  5. Connect and verify DocumentDB

    On Connect and verify, fill in the connection settings. Every field except Use TLS is required.

    SettingWhat to enter
    Cluster endpointThe cluster endpoint from the AWS console. With PrivateLink, Artie fills in the connection’s DNS entry and locks the field.
    PortThe cluster port. Defaults to 27017.
    UserThe service account’s user name, artie in the script.
    PasswordThe service account’s password.
    Use TLSOn by default. Artie encrypts the connection and doesn’t verify the cluster’s certificate. Artie turns it off when you link a PrivateLink connection, and you can turn it back on.
    Database nameThe database to replicate. It must have change streams enabled.

    Select Verify source. The step shows Source verified when the check passes.

Set the change stream retention

DocumentDB keeps change stream events for 3 hours by default, then deletes them. A pipeline that is paused or behind for longer can’t resume where it stopped. Depending on the error, it either fails until you act, or restarts from the current position and skips the changes in between.

Either way, backfill the pipeline’s tables with Empty tables first to recover the missed changes. The default, Keep existing rows, leaves documents deleted during the gap in the destination. Artie reads one change stream for the whole database, so the gap covers every table in the pipeline.

Raise change_stream_log_retention_duration in the cluster parameter group to cover how long you might pause the pipeline. The maximum is 7 days. See Using change streams with Amazon DocumentDB.

Advanced

These settings are optional.

Cast all columns to string

DocumentDB collections have no enforced schema, so different documents can store the same field with different types. By default, Artie infers the column type from the first non-null value it sees.

With Cast all columns to string on, Artie stores every column as a string as it is discovered, whatever its BSON type. That includes the primary key. Nested objects are stored as JSON strings. System columns (__artie_*) keep their own types.

The setting applies to new columns as they are discovered. Existing destination columns keep their types.

Kafka destinations don’t have this setting. For other destinations, find it in one of two places:

  • During setup: the destination’s Connect and verify step, under Advanced options.
  • On an existing pipeline: the Destination tab, under Advanced settings.

Enable client-side full document lookup

By default, Artie asks DocumentDB to attach the full document to each update event. When the document plus the event’s metadata exceeds the 16 MB BSON limit, the read fails with a BSONObjectTooLarge error.

With client-side lookup on, Artie fetches the document itself with a FindOne query for each update event. Turn it on in one of two places:

  • During setup: the source’s Connect and verify step, under Advanced options → Client-side document lookup.
  • On an existing pipeline: the Source tab, under Advanced settings → Enable client-side full document lookup.

Next steps

Was this page helpful?