Hi

Nice one Pasquale. I wonder if the docs are highlighting this? Maybe
we can add this as an example.
PR is welcome, we love contributions.

You can do this in the adoc file in src/main/docs of the component.
You can find that on github

On Wed, Apr 29, 2020 at 9:35 AM Pasquale Congiusti
<pasquale.congiu...@gmail.com> wrote:
>
> Hi Reji,
> actually you're providing a String type to your body, and Mongo does not
> treat the "_id" field as a String but as an ObjectId type.
>
> Please, change your setBody method to:
>
> .setBody(constant(new ObjectId("5ea1c4ae0911be2db0008909")))
>
> and everything should work as expected.
>
> Cheers,
> Pasquale.
>
> On Mon, Apr 27, 2020 at 4:07 PM Reji Mathews <reji.math...@huawei.com>
> wrote:
>
> > Hello Camel Community
> >
> > I am trying to use camel to query records based on mongo id with operation
> > "findById". Following is the route snippet
> >
> > public void configure() throws Exception {
> >     from("jetty:http://0.0.0.0:8081/mongo?httpMethodRestrict=GET";)
> >             .setBody(constant("5ea1c4ae0911be2db0008909"))
> >
> > .to("mongodb:mongoClient?database=connectortesting&operation=findById&collection=requests")
> >             .log("Mongo response ${body}")
> >             .end();
> > }
> >
> > I have following records in my test db
> >
> > > db.requests.find({});
> > { "_id" : ObjectId("5ea1c4ae0911be2db0008909"), "name" : "mark", "age" :
> > 40, "address" : "toronto, canada", "work" : { "company" : "mycompany",
> > "company_phone" : "+1437447xxxx" } }
> > { "_id" : ObjectId("5ea1f4df5e8c086e869250e3"), "name" : "mark", "age" :
> > 43, "address" : "toronto, canada", "work" : { "company" : " mycompany ",
> > "company_phone" : "+143744xxxxx" } }
> > { "_id" : ObjectId("5ea1f4f05e8c086e869250e4"), "name" : "hima", "age" :
> > 65, "address" : "toronto, canada", "work" : { "company" : " mycompany ",
> > "company_phone" : "+143744xxxxx" } }
> > { "_id" : ObjectId("5ea1f4f75e8c086e869250e5"), "name" : "paul", "age" :
> > 45, "address" : "toronto, canada", "work" : { "company" : " mycompany ",
> > "company_phone" : "+1437xxxxxxxx" } }
> > { "_id" : ObjectId("5ea1f4fd5e8c086e869250e6"), "name" : "tim", "age" :
> > 34, "address" : "toronto, canada", "work" : { "company" : " mycompany ",
> > "company_phone" : "+143744xxxxxx" } }
> >
> > I was expecting mongodb component to return 1st record where mongoId
> > matches "_id" but I get an empty result set. Am I doing something different
> > than expected here?
> >
> > MongoDB documentation says "This operation retrieves only one element from
> > the collection whose _id field matches the content of the IN message body"
> > . Hence ideally, this should return first record
> >
> > PS:  I am using camel version 2.24.0
> >
> > Cheers
> >
> >



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to