This is an automated email from the ASF dual-hosted git repository.
oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new e25fd058e chore: the MongoDB Kamelets take a connection string (#3170)
(#3200)
e25fd058e is described below
commit e25fd058e59a0d820b6bf90440232cdc36cc4f52
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 18 15:13:08 2026 +0100
chore: the MongoDB Kamelets take a connection string (#3170) (#3200)
mongodb-source, mongodb-sink and mongodb-changes-stream-source take an
optional connectionString, such as the mongodb+srv:// string of MongoDB
Atlas. It is passed RAW to the connectionUriString endpoint option, so the
endpoint creates its own client from it (CAMEL-27056, Camel 4.24). A
user defined in a database other than admin logs in with authSource in
the string; the bean the Kamelets use with hosts cannot take authSource,
and the endpoint authSource option is used only when the endpoint builds
its client from hosts.
The SslAwareMongoClient built from hosts, username, password, ssl and
sslValidationEnabled is now set as the mongoConnection of the template
component instead of on the endpoint, because mongoConnection on the
endpoint wins over connectionUriString. When connectionString is not set,
the endpoint uses that same client, so the old way works as before; the
endpoint URI only loses the mongoConnection=#mongo-client parameter.
hosts is no longer required. With neither hosts nor connectionString,
the Kamelet fails to start with "The connection string contains an
empty host" instead of waiting 30 seconds for a host named null.
connectionString is format: password with the credentials descriptor.
The descriptions also say which characters must be percent-encoded in a
password, which applied to the password option already.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../mongodb-changes-stream-source-description.adoc | 42 ++++++++++++++++++++--
.../ROOT/partials/mongodb-sink-description.adoc | 42 ++++++++++++++++++++--
.../ROOT/partials/mongodb-source-description.adoc | 38 +++++++++++++++++++-
.../mongodb-changes-stream-source.kamelet.yaml | 31 ++++++++++------
kamelets/mongodb-sink.kamelet.yaml | 31 ++++++++++------
kamelets/mongodb-source.kamelet.yaml | 31 ++++++++++------
.../main/resources/META-INF/kamelets-index.json | 6 ++--
.../mongodb-changes-stream-source.kamelet.yaml | 31 ++++++++++------
.../resources/kamelets/mongodb-sink.kamelet.yaml | 31 ++++++++++------
.../resources/kamelets/mongodb-source.kamelet.yaml | 31 ++++++++++------
10 files changed, 239 insertions(+), 75 deletions(-)
diff --git
a/docs/modules/ROOT/partials/mongodb-changes-stream-source-description.adoc
b/docs/modules/ROOT/partials/mongodb-changes-stream-source-description.adoc
index e359a751b..e0299671a 100644
--- a/docs/modules/ROOT/partials/mongodb-changes-stream-source-description.adoc
+++ b/docs/modules/ROOT/partials/mongodb-changes-stream-source-description.adoc
@@ -4,8 +4,10 @@
This Kamelet connects to MongoDB with:
-- Username and password authentication (optional), for a user defined in the
`admin` database
-- TLS, on by default (`ssl`); set `ssl` to false for a MongoDB without TLS
+- `hosts`, with username and password authentication (optional) for a user
defined in the `admin` database, and
+ TLS on by default (`ssl`); set `ssl` to false for a MongoDB without TLS
+- or a MongoDB connection string (`connectionString`), such as the
`mongodb+srv://` string of MongoDB Atlas; see
+ below
=== Output format
@@ -17,7 +19,7 @@ Change streams need a replica set or a sharded cluster.
The Kamelet requires database connection parameters:
-- `hosts`: the members of the replica set, as `host:port`
+- `hosts` (the members of the replica set, as `host:port`) or
`connectionString`
- `database` and `collection`: the collection to watch
- `streamFilter` (optional): a `$match` stage that chooses the changes to send
@@ -41,3 +43,37 @@ The route below logs each document inserted into the
`orders` collection.
- to:
uri: "kamelet:log-sink"
----
+
+=== Connecting with a connection string
+
+Set either `hosts` or `connectionString`. Use `connectionString` to connect to
MongoDB Atlas with its
+`mongodb+srv://` string, to log in as a user defined in a database other than
`admin` (with `authSource`), or to give
+other settings of the MongoDB connection string, such as `replicaSet` or
`tls`. When it is set, `hosts`, `username`,
+`password`, `ssl` and `sslValidationEnabled` are not used, and TLS is used as
the string says: always with
+`mongodb+srv://`, and with `mongodb://` only when it has `tls=true`.
+
+Write `@`, `/`, `:` and `%` in the user name or the password as `%40`, `%2F`,
`%3A` and `%25`. The connection string
+holds the password, so keep it in a secret, like the `password` option.
+
+With MongoDB Atlas, copy the string from the Connect dialog of the cluster:
+
+[source,yaml,subs='+attributes,macros']
+----
+- route:
+ from:
+ uri: "kamelet:mongodb-changes-stream-source"
+ parameters:
+ connectionString:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
+ database: "shop"
+ collection: "orders"
+ steps:
+ - to:
+ uri: "kamelet:log-sink"
+----
+
+For a user defined in the `shop` database, on a MongoDB without TLS:
+
+[source,yaml,subs='+attributes,macros']
+----
+connectionString:
"mongodb://shopuser:[email protected]:27017,mongo2.example.com:27017/?authSource=shop&replicaSet=rs0"
+----
diff --git a/docs/modules/ROOT/partials/mongodb-sink-description.adoc
b/docs/modules/ROOT/partials/mongodb-sink-description.adoc
index dfa854b78..707b1755c 100644
--- a/docs/modules/ROOT/partials/mongodb-sink-description.adoc
+++ b/docs/modules/ROOT/partials/mongodb-sink-description.adoc
@@ -10,7 +10,7 @@ The Kamelet supports SSL/TLS encryption for secure
connections to MongoDB. SSL i
=== Authentication
-Optional username and password authentication is supported for secured MongoDB
instances. The Kamelet uses SSL-aware MongoDB client connections for secure
data transmission.
+Optional username and password authentication is supported for secured MongoDB
instances, for a user defined in the `admin` database. The Kamelet uses
SSL-aware MongoDB client connections for secure data transmission. For MongoDB
Atlas, or a user defined in another database, use a connection string instead,
as shown below.
=== Write Operations
@@ -22,4 +22,42 @@ Configurable write concern levels ensure data durability and
consistency based o
=== Collection Management
-The Kamelet can optionally create collections during initialization if they
don't exist (`createCollection`). When `createCollection` is false, the
default, the Kamelet fails to start if the collection does not exist.
\ No newline at end of file
+The Kamelet can optionally create collections during initialization if they
don't exist (`createCollection`). When `createCollection` is false, the
default, the Kamelet fails to start if the collection does not exist.
+
+=== Connecting with a connection string
+
+Set either `hosts` or `connectionString`. Use `connectionString` to connect to
MongoDB Atlas with its
+`mongodb+srv://` string, to log in as a user defined in a database other than
`admin` (with `authSource`), or to give
+other settings of the MongoDB connection string, such as `replicaSet` or
`tls`. When it is set, `hosts`, `username`,
+`password`, `ssl` and `sslValidationEnabled` are not used, and TLS is used as
the string says: always with
+`mongodb+srv://`, and with `mongodb://` only when it has `tls=true`.
+
+Write `@`, `/`, `:` and `%` in the user name or the password as `%40`, `%2F`,
`%3A` and `%25`. The connection string
+holds the password, so keep it in a secret, like the `password` option.
+
+With MongoDB Atlas, copy the string from the Connect dialog of the cluster:
+
+[source,yaml,subs='+attributes,macros']
+----
+- route:
+ from:
+ uri: "kamelet:kafka-source"
+ parameters:
+ topic: "orders"
+ bootstrapServers: "kafka.example.com:9092"
+ saslAuthType: "NONE"
+ steps:
+ - to:
+ uri: "kamelet:mongodb-sink"
+ parameters:
+ connectionString:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
+ database: "shop"
+ collection: "orders"
+----
+
+For a user defined in the `shop` database, on a MongoDB without TLS:
+
+[source,yaml,subs='+attributes,macros']
+----
+connectionString:
"mongodb://shopuser:[email protected]:27017,mongo2.example.com:27017/?authSource=shop&replicaSet=rs0"
+----
diff --git a/docs/modules/ROOT/partials/mongodb-source-description.adoc
b/docs/modules/ROOT/partials/mongodb-source-description.adoc
index a5b4e2ae5..b08a7487c 100644
--- a/docs/modules/ROOT/partials/mongodb-source-description.adoc
+++ b/docs/modules/ROOT/partials/mongodb-source-description.adoc
@@ -8,7 +8,9 @@ This Kamelet supports MongoDB authentication using username and
password credent
The MongoDB Source Kamelet supports the following configurations:
-- **Hosts**: MongoDB server hosts and ports (required)
+- **Hosts**: MongoDB server hosts and ports; set either this or the connection
string
+- **Connection String**: a MongoDB connection string, such as the
`mongodb+srv://` string of MongoDB Atlas, used
+ instead of the hosts, username, password and SSL settings
- **Collection**: MongoDB collection name to read; it must be a capped
collection (required)
- **Database**: MongoDB database name (required)
- **Username**: Username for authentication (optional)
@@ -69,3 +71,37 @@ The collection must be capped, or the Kamelet fails to
start. A capped collectio
----
db.createCollection("events", { capped: true, size: 100000 })
----
+
+=== Connecting with a connection string
+
+Set either `hosts` or `connectionString`. Use `connectionString` to connect to
MongoDB Atlas with its
+`mongodb+srv://` string, to log in as a user defined in a database other than
`admin` (with `authSource`), or to give
+other settings of the MongoDB connection string, such as `replicaSet` or
`tls`. When it is set, `hosts`, `username`,
+`password`, `ssl` and `sslValidationEnabled` are not used, and TLS is used as
the string says: always with
+`mongodb+srv://`, and with `mongodb://` only when it has `tls=true`.
+
+Write `@`, `/`, `:` and `%` in the user name or the password as `%40`, `%2F`,
`%3A` and `%25`. The connection string
+holds the password, so keep it in a secret, like the `password` option.
+
+With MongoDB Atlas, copy the string from the Connect dialog of the cluster:
+
+[source,yaml,subs='+attributes,macros']
+----
+- route:
+ from:
+ uri: "kamelet:mongodb-source"
+ parameters:
+ connectionString:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
+ database: "logs"
+ collection: "app_logs"
+ steps:
+ - to:
+ uri: "kamelet:log-sink"
+----
+
+For a user defined in the `shop` database, on a MongoDB without TLS:
+
+[source,yaml,subs='+attributes,macros']
+----
+connectionString:
"mongodb://shopuser:[email protected]:27017,mongo2.example.com:27017/?authSource=shop&replicaSet=rs0"
+----
diff --git a/kamelets/mongodb-changes-stream-source.kamelet.yaml
b/kamelets/mongodb-changes-stream-source.kamelet.yaml
index 706364339..298492f3e 100644
--- a/kamelets/mongodb-changes-stream-source.kamelet.yaml
+++ b/kamelets/mongodb-changes-stream-source.kamelet.yaml
@@ -37,18 +37,25 @@ spec:
Output: the body is JSON text. For an insert or a replace, it is the
whole new document; for an update, the text `null`; for a delete, an object
with only the `_id` of the deleted document. The
`CamelMongoDbStreamOperationType` header says what happened (`insert`,
`update`, `replace` or `delete`), and the `_id` header holds the `_id` of the
document.
- Good to know: only changes made after the Kamelet starts are sent.
MongoDB offers change streams only on a replica set or a sharded cluster, not
on a single standalone server. It connects with TLS by default; set `ssl` to
false for a MongoDB without TLS, such as a local one.
+ Good to know: only changes made after the Kamelet starts are sent.
MongoDB offers change streams only on a replica set or a sharded cluster, not
on a single standalone server. Set either `hosts` or `connectionString`. With
`hosts`, it connects with TLS by default; set `ssl` to false for a MongoDB
without TLS, such as a local one. With `connectionString`, such as the
`mongodb+srv://` string of MongoDB Atlas, it connects only as that string says,
and `hosts`, `username`, `password`, [...]
required:
- - hosts
- collection
- database
type: object
properties:
hosts:
title: MongoDB Hosts
- description: The address of one or more members of the MongoDB replica
set or sharded cluster, as `host:port`, separated by commas. MongoDB uses port
27017 unless it was set up otherwise.
+ description: The address of one or more members of the MongoDB replica
set or sharded cluster, as `host:port`, separated by commas. MongoDB uses port
27017 unless it was set up otherwise. Set either `hosts` or `connectionString`.
When neither is set, the Kamelet fails to start with the error `The connection
string contains an empty host`.
type: string
example: mongo1.example.com:27017,mongo2.example.com:27017
+ connectionString:
+ title: Connection String
+ description: "The MongoDB connection string, which starts with
`mongodb://` or `mongodb+srv://`, such as the one MongoDB Atlas shows under
Connect. Use it instead of `hosts` for MongoDB Atlas, for a user defined in a
database other than `admin` (add `authSource`, such as `?authSource=shop`), or
for settings such as `replicaSet` or `tls`. When it is set, `hosts`,
`username`, `password`, `ssl` and `sslValidationEnabled` are not used. TLS is
used as the string says: always with `mon [...]
+ type: string
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ example:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
collection:
title: MongoDB Collection
description: The name of the collection to watch for changes.
@@ -56,25 +63,25 @@ spec:
example: orders
password:
title: MongoDB Password
- description: The password of the MongoDB user `username`.
+ description: The password of the MongoDB user `username`. Write `@`,
`/`, `:` and `%` in it as `%40`, `%2F`, `%3A` and `%25`.
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
username:
title: MongoDB Username
- description: The MongoDB user to log in as, defined in the `admin`
database. Leave it empty for a MongoDB that does not ask for a login.
+ description: The MongoDB user to log in as, defined in the `admin`
database. For a user defined in another database, use `connectionString` with
`authSource` instead. Leave it empty for a MongoDB that does not ask for a
login.
type: string
x-descriptors:
- urn:camel:group:credentials
ssl:
title: Use TLS
- description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS.
+ description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS. Not used with `connectionString`.
type: boolean
default: true
sslValidationEnabled:
title: Check TLS Certificate
- description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted.
+ description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted. Not used with `connectionString`.
type: boolean
default: true
database:
@@ -108,18 +115,20 @@ spec:
- "camel:jackson3"
template:
beans:
- - name: local-mongodb
- type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
- name: mongo-client
type: "#class:org.apache.camel.component.mongodb.SslAwareMongoClient"
properties:
password: "{{?password}}"
username: "{{?username}}"
- hosts: "{{hosts}}"
+ hosts: "{{hosts:}}"
ssl: "{{ssl}}"
sslValidationEnabled: "{{sslValidationEnabled}}"
+ - name: local-mongodb
+ type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
+ properties:
+ mongoConnection: "#{{mongo-client}}"
from:
- uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&mongoConnection=#{{mongo-client}}"
+ uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&connectionUriString=RAW({{?connectionString}})"
steps:
- marshal:
json: {}
diff --git a/kamelets/mongodb-sink.kamelet.yaml
b/kamelets/mongodb-sink.kamelet.yaml
index e3d603121..1e8ca94d5 100644
--- a/kamelets/mongodb-sink.kamelet.yaml
+++ b/kamelets/mongodb-sink.kamelet.yaml
@@ -39,18 +39,25 @@ spec:
Output: the body afterwards is the document that was stored, as a Map
with its `_id`, and the `CamelMongoOid` header holds that `_id`.
- Good to know: a document whose `_id` is already in the collection fails:
the Kamelet only inserts, and the `db-upsert` and `ce-dbupsert` headers do not
change that. With `createCollection` false, the default, the Kamelet fails to
start when the collection does not exist yet. It connects with TLS by default;
set `ssl` to false for a MongoDB without TLS, such as a local one.
+ Good to know: a document whose `_id` is already in the collection fails:
the Kamelet only inserts, and the `db-upsert` and `ce-dbupsert` headers do not
change that. With `createCollection` false, the default, the Kamelet fails to
start when the collection does not exist yet. Set either `hosts` or
`connectionString`. With `hosts`, it connects with TLS by default; set `ssl` to
false for a MongoDB without TLS, such as a local one. With `connectionString`,
such as the `mongodb+srv://` [...]
required:
- - hosts
- collection
- database
type: object
properties:
hosts:
title: MongoDB Hosts
- description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members.
+ description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members. Set either `hosts` or
`connectionString`. When neither is set, the Kamelet fails to start with the
error `The connection string contains an empty host`.
type: string
example: mongo1.example.com:27017,mongo2.example.com:27017
+ connectionString:
+ title: Connection String
+ description: "The MongoDB connection string, which starts with
`mongodb://` or `mongodb+srv://`, such as the one MongoDB Atlas shows under
Connect. Use it instead of `hosts` for MongoDB Atlas, for a user defined in a
database other than `admin` (add `authSource`, such as `?authSource=shop`), or
for settings such as `replicaSet` or `tls`. When it is set, `hosts`,
`username`, `password`, `ssl` and `sslValidationEnabled` are not used. TLS is
used as the string says: always with `mon [...]
+ type: string
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ example:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
collection:
title: MongoDB Collection
description: The name of the collection to insert the documents into.
@@ -58,25 +65,25 @@ spec:
example: orders
password:
title: MongoDB Password
- description: The password of the MongoDB user `username`.
+ description: The password of the MongoDB user `username`. Write `@`,
`/`, `:` and `%` in it as `%40`, `%2F`, `%3A` and `%25`.
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
username:
title: MongoDB Username
- description: The MongoDB user to log in as, defined in the `admin`
database. Leave it empty for a MongoDB that does not ask for a login.
+ description: The MongoDB user to log in as, defined in the `admin`
database. For a user defined in another database, use `connectionString` with
`authSource` instead. Leave it empty for a MongoDB that does not ask for a
login.
type: string
x-descriptors:
- urn:camel:group:credentials
ssl:
title: Use TLS
- description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS.
+ description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS. Not used with `connectionString`.
type: boolean
default: true
sslValidationEnabled:
title: Check TLS Certificate
- description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted.
+ description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted. Not used with `connectionString`.
type: boolean
default: true
database:
@@ -110,18 +117,20 @@ spec:
- "camel:jackson3"
template:
beans:
- - name: local-mongodb
- type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
- name: mongo-client
type: "#class:org.apache.camel.component.mongodb.SslAwareMongoClient"
properties:
password: "{{?password}}"
username: "{{?username}}"
- hosts: "{{hosts}}"
+ hosts: "{{hosts:}}"
ssl: "{{ssl}}"
sslValidationEnabled: "{{sslValidationEnabled}}"
+ - name: local-mongodb
+ type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
+ properties:
+ mongoConnection: "#{{mongo-client}}"
from:
uri: kamelet:source
steps:
- to:
- uri:
"{{local-mongodb}}:test?createCollection={{?createCollection}}&writeConcern={{?writeConcern}}&collection={{collection}}&database={{database}}&operation=insert&mongoConnection=#{{mongo-client}}"
+ uri:
"{{local-mongodb}}:test?createCollection={{?createCollection}}&writeConcern={{?writeConcern}}&collection={{collection}}&database={{database}}&operation=insert&connectionUriString=RAW({{?connectionString}})"
diff --git a/kamelets/mongodb-source.kamelet.yaml
b/kamelets/mongodb-source.kamelet.yaml
index 88e29f84d..e551dc2be 100644
--- a/kamelets/mongodb-source.kamelet.yaml
+++ b/kamelets/mongodb-source.kamelet.yaml
@@ -37,18 +37,25 @@ spec:
Output: the body is one document as JSON text. An `_id` that is an
ObjectId comes out as an object with only its time (`timestamp` and `date`),
not as the ID text, and the format of dates depends on the Camel version. The
`CamelMongoDbDatabase` and `CamelMongoDbCollection` headers name where the
document comes from.
- Good to know: the collection must be capped (created with a fixed size),
or the Kamelet fails to start. Each time the integration starts, it reads the
whole collection again from the start, unless `persistentTailTracking` is true.
It connects with TLS by default; set `ssl` to false for a MongoDB without TLS,
such as a local one.
+ Good to know: the collection must be capped (created with a fixed size),
or the Kamelet fails to start. Each time the integration starts, it reads the
whole collection again from the start, unless `persistentTailTracking` is true.
Set either `hosts` or `connectionString`. With `hosts`, it connects with TLS by
default; set `ssl` to false for a MongoDB without TLS, such as a local one.
With `connectionString`, such as the `mongodb+srv://` string of MongoDB Atlas,
it connects only as [...]
required:
- - hosts
- collection
- database
type: object
properties:
hosts:
title: MongoDB Hosts
- description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members.
+ description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members. Set either `hosts` or
`connectionString`. When neither is set, the Kamelet fails to start with the
error `The connection string contains an empty host`.
type: string
example: mongo1.example.com:27017,mongo2.example.com:27017
+ connectionString:
+ title: Connection String
+ description: "The MongoDB connection string, which starts with
`mongodb://` or `mongodb+srv://`, such as the one MongoDB Atlas shows under
Connect. Use it instead of `hosts` for MongoDB Atlas, for a user defined in a
database other than `admin` (add `authSource`, such as `?authSource=shop`), or
for settings such as `replicaSet` or `tls`. When it is set, `hosts`,
`username`, `password`, `ssl` and `sslValidationEnabled` are not used. TLS is
used as the string says: always with `mon [...]
+ type: string
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ example:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
collection:
title: MongoDB Collection
description: The name of the capped collection to read.
@@ -56,25 +63,25 @@ spec:
example: events
password:
title: MongoDB Password
- description: The password of the MongoDB user `username`.
+ description: The password of the MongoDB user `username`. Write `@`,
`/`, `:` and `%` in it as `%40`, `%2F`, `%3A` and `%25`.
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
username:
title: MongoDB Username
- description: The MongoDB user to log in as, defined in the `admin`
database. Leave it empty for a MongoDB that does not ask for a login.
+ description: The MongoDB user to log in as, defined in the `admin`
database. For a user defined in another database, use `connectionString` with
`authSource` instead. Leave it empty for a MongoDB that does not ask for a
login.
type: string
x-descriptors:
- urn:camel:group:credentials
ssl:
title: Use TLS
- description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS.
+ description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS. Not used with `connectionString`.
type: boolean
default: true
sslValidationEnabled:
title: Check TLS Certificate
- description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted.
+ description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted. Not used with `connectionString`.
type: boolean
default: true
database:
@@ -113,18 +120,20 @@ spec:
- "camel:jackson3"
template:
beans:
- - name: local-mongodb
- type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
- name: mongo-client
type: "#class:org.apache.camel.component.mongodb.SslAwareMongoClient"
properties:
password: "{{?password}}"
username: "{{?username}}"
- hosts: "{{hosts}}"
+ hosts: "{{hosts:}}"
ssl: "{{ssl}}"
sslValidationEnabled: "{{sslValidationEnabled}}"
+ - name: local-mongodb
+ type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
+ properties:
+ mongoConnection: "#{{mongo-client}}"
from:
- uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&persistentTailTracking={{persistentTailTracking}}&tailTrackIncreasingField={{?tailTrackIncreasingField}}&mongoConnection=#{{mongo-client}}"
+ uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&persistentTailTracking={{persistentTailTracking}}&tailTrackIncreasingField={{?tailTrackIncreasingField}}&connectionUriString=RAW({{?connectionString}})"
steps:
- marshal:
json: {}
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 94441a91e..3f420bb8c 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -1545,7 +1545,7 @@
"supportLevel" : "Stable",
"title" : "MongoDB Changes Stream Source",
"summary" : "Sends a message for each change to a collection of a MongoDB
database, such as a document inserted, updated or deleted, as it happens.",
- "description" : "Sends a message for each change to a collection of a
MongoDB database, such as a document inserted, updated or deleted, as it
happens.\n\nUse it to react to changes in MongoDB, for example to copy new
orders to another system or to keep a cache or a search index up to date. To
read the documents of a capped collection from the start, use `mongodb-source`.
To write documents, use `mongodb-sink`.\n\nOutput: the body is JSON text. For
an insert or a replace, it is the w [...]
+ "description" : "Sends a message for each change to a collection of a
MongoDB database, such as a document inserted, updated or deleted, as it
happens.\n\nUse it to react to changes in MongoDB, for example to copy new
orders to another system or to keep a cache or a search index up to date. To
read the documents of a capped collection from the start, use `mongodb-source`.
To write documents, use `mongodb-sink`.\n\nOutput: the body is JSON text. For
an insert or a replace, it is the w [...]
"group" : "MongoDB",
"namespace" : "Nosql",
"provider" : "Apache Software Foundation"
@@ -1555,7 +1555,7 @@
"supportLevel" : "Stable",
"title" : "MongoDB Sink",
"summary" : "Inserts each message as a new document into a collection of a
MongoDB database.",
- "description" : "Inserts each message as a new document into a collection
of a MongoDB database.\n\nUse it to store events, orders or other records as
documents in MongoDB, for example each message that arrives on a Kafka topic.
To read documents, use `mongodb-source` or
`mongodb-changes-stream-source`.\n\nInput: the body is one document, as a JSON
object in text, such as `{\"item\":\"book\",\"qty\":2}`. When it has no `_id`
field, MongoDB gives the document a new ObjectId. A JSON ar [...]
+ "description" : "Inserts each message as a new document into a collection
of a MongoDB database.\n\nUse it to store events, orders or other records as
documents in MongoDB, for example each message that arrives on a Kafka topic.
To read documents, use `mongodb-source` or
`mongodb-changes-stream-source`.\n\nInput: the body is one document, as a JSON
object in text, such as `{\"item\":\"book\",\"qty\":2}`. When it has no `_id`
field, MongoDB gives the document a new ObjectId. A JSON ar [...]
"group" : "MongoDB",
"namespace" : "Nosql",
"provider" : "Apache Software Foundation"
@@ -1565,7 +1565,7 @@
"supportLevel" : "Stable",
"title" : "MongoDB Source",
"summary" : "Reads the documents of a capped collection in a MongoDB
database, first those already there and then each new one as it is added, one
message per document, as JSON text.",
- "description" : "Reads the documents of a capped collection in a MongoDB
database, first those already there and then each new one as it is added, one
message per document, as JSON text.\n\nUse it to pass on records that an
application appends to a capped collection, such as log entries or events, as
they arrive. For a normal collection, or to also see updates and deletes, use
`mongodb-changes-stream-source`. To write documents, use
`mongodb-sink`.\n\nOutput: the body is one document [...]
+ "description" : "Reads the documents of a capped collection in a MongoDB
database, first those already there and then each new one as it is added, one
message per document, as JSON text.\n\nUse it to pass on records that an
application appends to a capped collection, such as log entries or events, as
they arrive. For a normal collection, or to also see updates and deletes, use
`mongodb-changes-stream-source`. To write documents, use
`mongodb-sink`.\n\nOutput: the body is one document [...]
"group" : "MongoDB",
"namespace" : "Nosql",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
index 706364339..298492f3e 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-changes-stream-source.kamelet.yaml
@@ -37,18 +37,25 @@ spec:
Output: the body is JSON text. For an insert or a replace, it is the
whole new document; for an update, the text `null`; for a delete, an object
with only the `_id` of the deleted document. The
`CamelMongoDbStreamOperationType` header says what happened (`insert`,
`update`, `replace` or `delete`), and the `_id` header holds the `_id` of the
document.
- Good to know: only changes made after the Kamelet starts are sent.
MongoDB offers change streams only on a replica set or a sharded cluster, not
on a single standalone server. It connects with TLS by default; set `ssl` to
false for a MongoDB without TLS, such as a local one.
+ Good to know: only changes made after the Kamelet starts are sent.
MongoDB offers change streams only on a replica set or a sharded cluster, not
on a single standalone server. Set either `hosts` or `connectionString`. With
`hosts`, it connects with TLS by default; set `ssl` to false for a MongoDB
without TLS, such as a local one. With `connectionString`, such as the
`mongodb+srv://` string of MongoDB Atlas, it connects only as that string says,
and `hosts`, `username`, `password`, [...]
required:
- - hosts
- collection
- database
type: object
properties:
hosts:
title: MongoDB Hosts
- description: The address of one or more members of the MongoDB replica
set or sharded cluster, as `host:port`, separated by commas. MongoDB uses port
27017 unless it was set up otherwise.
+ description: The address of one or more members of the MongoDB replica
set or sharded cluster, as `host:port`, separated by commas. MongoDB uses port
27017 unless it was set up otherwise. Set either `hosts` or `connectionString`.
When neither is set, the Kamelet fails to start with the error `The connection
string contains an empty host`.
type: string
example: mongo1.example.com:27017,mongo2.example.com:27017
+ connectionString:
+ title: Connection String
+ description: "The MongoDB connection string, which starts with
`mongodb://` or `mongodb+srv://`, such as the one MongoDB Atlas shows under
Connect. Use it instead of `hosts` for MongoDB Atlas, for a user defined in a
database other than `admin` (add `authSource`, such as `?authSource=shop`), or
for settings such as `replicaSet` or `tls`. When it is set, `hosts`,
`username`, `password`, `ssl` and `sslValidationEnabled` are not used. TLS is
used as the string says: always with `mon [...]
+ type: string
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ example:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
collection:
title: MongoDB Collection
description: The name of the collection to watch for changes.
@@ -56,25 +63,25 @@ spec:
example: orders
password:
title: MongoDB Password
- description: The password of the MongoDB user `username`.
+ description: The password of the MongoDB user `username`. Write `@`,
`/`, `:` and `%` in it as `%40`, `%2F`, `%3A` and `%25`.
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
username:
title: MongoDB Username
- description: The MongoDB user to log in as, defined in the `admin`
database. Leave it empty for a MongoDB that does not ask for a login.
+ description: The MongoDB user to log in as, defined in the `admin`
database. For a user defined in another database, use `connectionString` with
`authSource` instead. Leave it empty for a MongoDB that does not ask for a
login.
type: string
x-descriptors:
- urn:camel:group:credentials
ssl:
title: Use TLS
- description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS.
+ description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS. Not used with `connectionString`.
type: boolean
default: true
sslValidationEnabled:
title: Check TLS Certificate
- description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted.
+ description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted. Not used with `connectionString`.
type: boolean
default: true
database:
@@ -108,18 +115,20 @@ spec:
- "camel:jackson3"
template:
beans:
- - name: local-mongodb
- type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
- name: mongo-client
type: "#class:org.apache.camel.component.mongodb.SslAwareMongoClient"
properties:
password: "{{?password}}"
username: "{{?username}}"
- hosts: "{{hosts}}"
+ hosts: "{{hosts:}}"
ssl: "{{ssl}}"
sslValidationEnabled: "{{sslValidationEnabled}}"
+ - name: local-mongodb
+ type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
+ properties:
+ mongoConnection: "#{{mongo-client}}"
from:
- uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&mongoConnection=#{{mongo-client}}"
+ uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&consumerType=changeStreams&streamFilter={{?streamFilter}}&connectionUriString=RAW({{?connectionString}})"
steps:
- marshal:
json: {}
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-sink.kamelet.yaml
index e3d603121..1e8ca94d5 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-sink.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-sink.kamelet.yaml
@@ -39,18 +39,25 @@ spec:
Output: the body afterwards is the document that was stored, as a Map
with its `_id`, and the `CamelMongoOid` header holds that `_id`.
- Good to know: a document whose `_id` is already in the collection fails:
the Kamelet only inserts, and the `db-upsert` and `ce-dbupsert` headers do not
change that. With `createCollection` false, the default, the Kamelet fails to
start when the collection does not exist yet. It connects with TLS by default;
set `ssl` to false for a MongoDB without TLS, such as a local one.
+ Good to know: a document whose `_id` is already in the collection fails:
the Kamelet only inserts, and the `db-upsert` and `ce-dbupsert` headers do not
change that. With `createCollection` false, the default, the Kamelet fails to
start when the collection does not exist yet. Set either `hosts` or
`connectionString`. With `hosts`, it connects with TLS by default; set `ssl` to
false for a MongoDB without TLS, such as a local one. With `connectionString`,
such as the `mongodb+srv://` [...]
required:
- - hosts
- collection
- database
type: object
properties:
hosts:
title: MongoDB Hosts
- description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members.
+ description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members. Set either `hosts` or
`connectionString`. When neither is set, the Kamelet fails to start with the
error `The connection string contains an empty host`.
type: string
example: mongo1.example.com:27017,mongo2.example.com:27017
+ connectionString:
+ title: Connection String
+ description: "The MongoDB connection string, which starts with
`mongodb://` or `mongodb+srv://`, such as the one MongoDB Atlas shows under
Connect. Use it instead of `hosts` for MongoDB Atlas, for a user defined in a
database other than `admin` (add `authSource`, such as `?authSource=shop`), or
for settings such as `replicaSet` or `tls`. When it is set, `hosts`,
`username`, `password`, `ssl` and `sslValidationEnabled` are not used. TLS is
used as the string says: always with `mon [...]
+ type: string
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ example:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
collection:
title: MongoDB Collection
description: The name of the collection to insert the documents into.
@@ -58,25 +65,25 @@ spec:
example: orders
password:
title: MongoDB Password
- description: The password of the MongoDB user `username`.
+ description: The password of the MongoDB user `username`. Write `@`,
`/`, `:` and `%` in it as `%40`, `%2F`, `%3A` and `%25`.
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
username:
title: MongoDB Username
- description: The MongoDB user to log in as, defined in the `admin`
database. Leave it empty for a MongoDB that does not ask for a login.
+ description: The MongoDB user to log in as, defined in the `admin`
database. For a user defined in another database, use `connectionString` with
`authSource` instead. Leave it empty for a MongoDB that does not ask for a
login.
type: string
x-descriptors:
- urn:camel:group:credentials
ssl:
title: Use TLS
- description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS.
+ description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS. Not used with `connectionString`.
type: boolean
default: true
sslValidationEnabled:
title: Check TLS Certificate
- description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted.
+ description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted. Not used with `connectionString`.
type: boolean
default: true
database:
@@ -110,18 +117,20 @@ spec:
- "camel:jackson3"
template:
beans:
- - name: local-mongodb
- type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
- name: mongo-client
type: "#class:org.apache.camel.component.mongodb.SslAwareMongoClient"
properties:
password: "{{?password}}"
username: "{{?username}}"
- hosts: "{{hosts}}"
+ hosts: "{{hosts:}}"
ssl: "{{ssl}}"
sslValidationEnabled: "{{sslValidationEnabled}}"
+ - name: local-mongodb
+ type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
+ properties:
+ mongoConnection: "#{{mongo-client}}"
from:
uri: kamelet:source
steps:
- to:
- uri:
"{{local-mongodb}}:test?createCollection={{?createCollection}}&writeConcern={{?writeConcern}}&collection={{collection}}&database={{database}}&operation=insert&mongoConnection=#{{mongo-client}}"
+ uri:
"{{local-mongodb}}:test?createCollection={{?createCollection}}&writeConcern={{?writeConcern}}&collection={{collection}}&database={{database}}&operation=insert&connectionUriString=RAW({{?connectionString}})"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-source.kamelet.yaml
index 88e29f84d..e551dc2be 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/mongodb-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/mongodb-source.kamelet.yaml
@@ -37,18 +37,25 @@ spec:
Output: the body is one document as JSON text. An `_id` that is an
ObjectId comes out as an object with only its time (`timestamp` and `date`),
not as the ID text, and the format of dates depends on the Camel version. The
`CamelMongoDbDatabase` and `CamelMongoDbCollection` headers name where the
document comes from.
- Good to know: the collection must be capped (created with a fixed size),
or the Kamelet fails to start. Each time the integration starts, it reads the
whole collection again from the start, unless `persistentTailTracking` is true.
It connects with TLS by default; set `ssl` to false for a MongoDB without TLS,
such as a local one.
+ Good to know: the collection must be capped (created with a fixed size),
or the Kamelet fails to start. Each time the integration starts, it reads the
whole collection again from the start, unless `persistentTailTracking` is true.
Set either `hosts` or `connectionString`. With `hosts`, it connects with TLS by
default; set `ssl` to false for a MongoDB without TLS, such as a local one.
With `connectionString`, such as the `mongodb+srv://` string of MongoDB Atlas,
it connects only as [...]
required:
- - hosts
- collection
- database
type: object
properties:
hosts:
title: MongoDB Hosts
- description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members.
+ description: The address of one or more MongoDB servers, as
`host:port`, separated by commas. MongoDB uses port 27017 unless it was set up
otherwise. For a replica set, list its members. Set either `hosts` or
`connectionString`. When neither is set, the Kamelet fails to start with the
error `The connection string contains an empty host`.
type: string
example: mongo1.example.com:27017,mongo2.example.com:27017
+ connectionString:
+ title: Connection String
+ description: "The MongoDB connection string, which starts with
`mongodb://` or `mongodb+srv://`, such as the one MongoDB Atlas shows under
Connect. Use it instead of `hosts` for MongoDB Atlas, for a user defined in a
database other than `admin` (add `authSource`, such as `?authSource=shop`), or
for settings such as `replicaSet` or `tls`. When it is set, `hosts`,
`username`, `password`, `ssl` and `sslValidationEnabled` are not used. TLS is
used as the string says: always with `mon [...]
+ type: string
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ example:
"mongodb+srv://myuser:[email protected]/?retryWrites=true&w=majority"
collection:
title: MongoDB Collection
description: The name of the capped collection to read.
@@ -56,25 +63,25 @@ spec:
example: events
password:
title: MongoDB Password
- description: The password of the MongoDB user `username`.
+ description: The password of the MongoDB user `username`. Write `@`,
`/`, `:` and `%` in it as `%40`, `%2F`, `%3A` and `%25`.
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
username:
title: MongoDB Username
- description: The MongoDB user to log in as, defined in the `admin`
database. Leave it empty for a MongoDB that does not ask for a login.
+ description: The MongoDB user to log in as, defined in the `admin`
database. For a user defined in another database, use `connectionString` with
`authSource` instead. Leave it empty for a MongoDB that does not ask for a
login.
type: string
x-descriptors:
- urn:camel:group:credentials
ssl:
title: Use TLS
- description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS.
+ description: Whether to connect with TLS (SSL). Set it to false for a
MongoDB that does not offer TLS. Not used with `connectionString`.
type: boolean
default: true
sslValidationEnabled:
title: Check TLS Certificate
- description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted.
+ description: Whether to check the certificate and the host name of the
server when `ssl` is true. Set it to false only for tests, as the connection
can then be intercepted. Not used with `connectionString`.
type: boolean
default: true
database:
@@ -113,18 +120,20 @@ spec:
- "camel:jackson3"
template:
beans:
- - name: local-mongodb
- type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
- name: mongo-client
type: "#class:org.apache.camel.component.mongodb.SslAwareMongoClient"
properties:
password: "{{?password}}"
username: "{{?username}}"
- hosts: "{{hosts}}"
+ hosts: "{{hosts:}}"
ssl: "{{ssl}}"
sslValidationEnabled: "{{sslValidationEnabled}}"
+ - name: local-mongodb
+ type: "#class:org.apache.camel.component.mongodb.MongoDbComponent"
+ properties:
+ mongoConnection: "#{{mongo-client}}"
from:
- uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&persistentTailTracking={{persistentTailTracking}}&tailTrackIncreasingField={{?tailTrackIncreasingField}}&mongoConnection=#{{mongo-client}}"
+ uri:
"{{local-mongodb}}:test?collection={{collection}}&database={{database}}&persistentTailTracking={{persistentTailTracking}}&tailTrackIncreasingField={{?tailTrackIncreasingField}}&connectionUriString=RAW({{?connectionString}})"
steps:
- marshal:
json: {}