Camel Mongo findById // empty results

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Camel Mongo findById // empty results

reji.mathews
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