Skip to main content
Version: 23.1

Create a MongoDB Sink Connector

The MongoDB Sink managed connector exports Redpanda structured data to a MongoDB database.

Prerequisites

You must have valid read and write credentials to a MongoDB database.

Create a MongoDB Sink connector

To create a MongoDB Sink connector:

  1. In Redpanda Cloud, click Connectors in the navigation menu, and then click Create Connector.

  2. Select Export to MongoDB Sink.

  3. On the Create Connector page, specify the following required connector configuration options:

    PropertyDescription
    Topics to exportA comma-separated list of the cluster topics you want to export to MongoDB.
    MongoDB Connection URLThe MongoDB connection URI string to connect to your MongoDB instance or cluster. For example, mongodb://locahost/.
    MongoDB usernameA valid MongoDB user.
    MongoDB passwordThe password for the account associated with the MongoDB user.
    MongoDB database nameThe name of an existing MongoDB database to store output files in.
    Kafka message key formatFormat of the key in the Kafka topic. Default is STRING.
    Kafka message value formatFormat of the value in the Kafka topic. Default is STRING.
    Default MongoDB collection name(Optional). Single sink collection name to write to. If following multiple topics, then this will be the default collection to which they are mapped.
    Max TasksMaximum number of tasks to use for this connector. The default is 1. Each task replicates exclusive set of partitions assigned to it.
    Connector nameGlobally-unique name to use for this connector.
  4. Click Next. Review the connector properties specified, then click Create.

Advanced MongoDB Sink connector configuration

In most instances, the preceding basic configuration properties are sufficient. If you require additional property settings, then specify any of the following optional advanced connector configuration properties by selecting Show advanced options on the Create Connector page:

PropertyDescription
CDC handlerThe CDC (change data capture) handler to use for processing. The MongoDB handler requires plain JSON or BSON format. The default is NONE.
Key projection typeThe type of key projection to use: either AllowList or BlockList.
Key projection listA comma-separated list of field names for key projection.
Type of value projection to use Use either AllowList or BlockListOnly use with Value projection list. The type of value projection to use: AllowList or BlockList. The default is NONE.
Value projection listA comma-separated list of field names for value projection.
Field renamer mappingAn inline JSON array with objects describing field name mappings. For example: [{"oldName":"key.fieldA","newName":"field1"},{"oldName":"value.xyz","newName":"abc"}].
Field used for timeName of the top level field used for time. Inserted documents must specify this field, and it must be of the BSON datetime type.
Field describing the seriesThe name of the top-level field that contains metadata in each time series document. The metadata in the specified field should be data that is used to label a unique series of documents. The metadata should rarely, if ever, change. This field is used to group related data and may be of any BSON type, except for array. The metadata field may not be the same as the timeField or _id.
Convert the field to a BSON datetime typeConverts the timeseries field to a BSON datetime type. If the value is a numeric value it will use the milliseconds from epoch. Any fractional parts are discarded. If the value is a STRING it will use the timeseries.timefield.auto.convert.date.format property to parse the date.
DateTimeFormatter pattern for the dateThe DateTimeFormatter pattern to use when converting string dates. Defaults to support ISO style date times. A string is expected to contain both the date and time. If the string only contains date information, then the time since epoch is taken from the start of that day. If a string representation does not contain a timezone offset, then the extracted date and time is interpreted as UTC.
Data expiry time in secondsThe amount of time in seconds that the data will be kept in MongoDB before being automatically deleted.
Data expiry timeThe expected interval between subsequent measurements for a time series. Possible values are "seconds", "minutes" or "hours".
Error toleranceError tolerance response during connector operation. Default value is none and signals that any error will result in an immediate connector task failure. Value of all changes the behavior to skip over problematic records.

Map data

Use the appropriate key or value converter (input data format) for your data as follows:

  • JSON when your messages are structured JSON. Select Message JSON contains schema, with the schema and payload fields.
  • AVRO when your messages contain AVRO-encoded messages, with schema stored in the Schema Registry.
  • STRING when your messages contain plaintext JSON.
  • BYTES when your messages contain BSON.

Test the connection

After the connector is created, verify that your new collections apper in your MongoDB database:

show collections

Troubleshoot

Issues are reported using a failed task error message.

MessageAction
Invalid value wrong_uri for configuration connection.uri: The connection string is invalid. Connection strings must start with either 'mongodb://' or 'mongodb+srv://Check to make sure the Connection URI is a valid MongoDB URL.
Unable to connect to the server.Check to ensure that the Connection URI is valid and that the MongoDB server accepts connections.
Invalid user permissions authentication failed. Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='user', source='admin', password=, mechanismProperties=}.Check to ensure that you specified valid username and password credentials.
DataException: Could not convert key `` into a BsonDocument.Make sure your message keys are valid JSONs or skip configuration for fields that require valid JSON keys.
DataException: Error: operationType field doc is missing.Make sure the input record format is correct (produced by a MongoDB source connector if you use MongoDB CDC handler).
DataException: Value document is missing or CDC operation is not a stringMake sure the input record format is correct (produced by a Debezium source connector if you use Debezium CDC handler).
JsonParseException: Unrecognized token 'text': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')Make sure the input record format is JSON.

Suggested reading

What do you like about this doc?




Optional: Share your email address if we can contact you about your feedback.

Let us know what we do well: