// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
[id="extensions-mongodb"]
= MongoDB
:page-aliases: extensions/mongodb.adoc
:linkattrs:
:cq-artifact-id: camel-quarkus-mongodb
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Perform operations on MongoDB documents and collections.
:cq-deprecated: false
:cq-jvm-since: 1.0.0
:cq-native-since: 1.0.0

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##1.0.0##
endif::[]

Perform operations on MongoDB documents and collections.

[id="extensions-mongodb-whats-inside"]
== What's inside

* xref:{cq-camel-components}::mongodb-component.adoc[MongoDB component], URI syntax: `mongodb:connectionBean`

Please refer to the above link for usage and configuration details.

[id="extensions-mongodb-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-mongodb[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-mongodb</artifactId>
</dependency>
----
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-mongodb-additional-camel-quarkus-configuration"]
== Additional Camel Quarkus configuration

The extension leverages the https://quarkus.io/guides/mongodb[Quarkus MongoDB Client] extension. The Mongo client can be configured
via the Quarkus MongoDB Client https://quarkus.io/guides/mongodb#configuration-reference[configuration options].

The Camel Quarkus MongoDB extension automatically registers a MongoDB client bean named `camelMongoClient`. This can be referenced in the mongodb endpoint URI
`connectionBean` path parameter. For example:

    from("direct:start")
    .to("mongodb:camelMongoClient?database=myDb&collection=myCollection&operation=findAll")

If your application needs to work with multiple MongoDB servers, you can create a "named" client and reference in your route by injecting a client and the related configuration as explained in the https://quarkus.io/guides/mongodb#named-mongo-client-injection[Quarkus MongoDB extension client injection]. For example:

....
//application.properties
quarkus.mongodb.mongoClient1.connection-string = mongodb://root:example@localhost:27017/
....
....
//Routes.java

    @ApplicationScoped
    public class Routes extends RouteBuilder {
        @Inject
        @MongoClientName("mongoClient1")
        MongoClient mongoClient1;

        @Override
        public void configure() throws Exception {
            from("direct:defaultServer")
                .to("mongodb:camelMongoClient?database=myDb&collection=myCollection&operation=findAll")

            from("direct:otherServer")
                .to("mongodb:mongoClient1?database=myOtherDb&collection=myOtherCollection&operation=findAll");
        }
    }
....

Note that when using named clients, the "default" `camelMongoClient` bean will still be produced. Refer to the Quarkus documentation on https://quarkus.io/guides/mongodb#multiple-mongodb-clients[Multiple MongoDB Clients] for more information.

