This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 26c213d  feat(mongodb): add a converter to ObjectId
26c213d is described below

commit 26c213d055149747c4686c40b612f9dab5870d53
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Thu Apr 30 09:32:34 2020 +0200

    feat(mongodb): add a converter to ObjectId
    
    * Adding a method to allow conversion to ObjectId type, used as default by 
MongoDB as _id field type.
    * Adding some doc to explain how to use it
    
    Closes CAMEL-14989
---
 components/camel-mongodb/src/main/docs/mongodb-component.adoc  | 10 ++++++++++
 .../component/mongodb/converters/MongoDbBasicConverters.java   |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/components/camel-mongodb/src/main/docs/mongodb-component.adoc 
b/components/camel-mongodb/src/main/docs/mongodb-component.adoc
index 1eb6722..b5d3bc4 100644
--- a/components/camel-mongodb/src/main/docs/mongodb-component.adoc
+++ b/components/camel-mongodb/src/main/docs/mongodb-component.adoc
@@ -203,6 +203,16 @@ from("direct:findById")
     .to("mock:resultFindById");
 ------------------------------------------------------------------------------
 
+Please, note that the default _id is treated by Mongo as and `ObjectId` type, 
so you may need to convert it properly.
+
+[source,java]
+------------------------------------------------------------------------------
+from("direct:findById")
+    .convertBodyTo(ObjectId.class)
+    .to("mongodb:myDb?database=flights&collection=tickets&operation=findById")
+    .to("mock:resultFindById");
+------------------------------------------------------------------------------
+
 [TIP]
 ====
 *Supports optional parameters*.
diff --git 
a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
 
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
index ee3efe8..7465947 100644
--- 
a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
+++ 
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/converters/MongoDbBasicConverters.java
@@ -41,6 +41,7 @@ import org.bson.codecs.configuration.CodecRegistries;
 import org.bson.codecs.configuration.CodecRegistry;
 import org.bson.conversions.Bson;
 import org.bson.json.JsonReader;
+import org.bson.types.ObjectId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,6 +69,11 @@ public final class MongoDbBasicConverters {
     }
 
     @Converter
+    public static ObjectId fromStringToObjectId(String s) {
+        return new ObjectId(s);
+    }
+
+    @Converter
     public static Document fromFileToDocument(File f, Exchange exchange) 
throws Exception {
         return fromInputStreamToDocument(new FileInputStream(f), exchange);
     }

Reply via email to