blob: 233fb058374f2696427590cdeadfd38a43e3c028 [file] [log] [blame]
== Camel MongoDB Example
This example shows how to use Camel MongoDB component. There are three REST endpoints that will trigger the MongoDB component for reading and for writing.
=== Run a MongoDB instance
You need to have an instance of MongoDB server running locally.
You can run it as a Docker container:
[source,sh]
----
docker run -d --name mongodb -p 27017:27017 mongo
----
=== Build
You will need to compile this example first:
[source,sh]
----
$ mvn compile
----
=== Run the Camel integration
You can now run your application by executing:
----
$ mvn exec:java
----
=== Make some test call
You can insert an "hello" document by POSTing to `/hello` endpoint:
----
$ curl -X POST -H "Content-Type: application/json" -d '{"text":"Hello from Camel"}' http://localhost:8081/hello
----
The result of the query is of type:
----
$ Document{{text=Hello from Camel, _id=<document-id>}}
----
You can read all the documents by requesting to `/` endpoint:
----
$ curl localhost:8081
----
You can also read a single document by setting the `id` query parameter to the target `<document-id>`:
----
$ curl "localhost:8081/hello?id=<document-id>"
----
=== Help and contributions
If you hit any problem using Camel or have some feedback, then please
https://camel.apache.org/community/support/[let us know].
We also love contributors, so
https://camel.apache.org/community/contributing/[get involved] :-)
The Camel riders!