You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Raul Kripalani <ra...@fusesource.com> on 2012/08/08 14:30:41 UTC

Re: Using timer and MongoDb queries

Hi Rich,

All you need to do is specify the query object as the body of the IN
message.

Ultimately, the query object should be a DBObject (i.e. a JSON object), but
the good news is that camel-mongodb supports automatic type conversions
from Strings and HashMaps!

So you could do the following:

from("timer://myTimer?period=30000")
    .setBody().constant("{\"foo\": \"bar\"}")

.to("mongodb:myDb?database=test&collection=test&operation=findAll&dynamicity=true")
    .to("stream:out");

This will return all objects that contain a field "foo" whose value is
"bar". Remember to escape inner quotes in the JSON object.

And you are right, this use case doesn't appear in the component's
documentation. I'll update straightaway.

Hope that helps.

P.S.: No need to use custom processors as Sam described. As of Camel 2.10,
there's a camel-mongodb component to interact with MongoDB databases
directly from your routes.

Thanks,

*Raúl Kripalani*
*Principal Consultant | FuseSource Corp.
raul@fusesource.com | fusesource.com <http://www.fusesource.com/>
skype: raul.fuse | twitter: @raulvk <http://twitter.com/raulvk>,
@fusenews<http://twitter.com/fusenews>
*
blog: F3 - Flashes From the
Field<http://blog.raulkr.net/?utm_source=fusesourceemail&utm_medium=email&utm_campaign=fusesourcemail>
aboutme: http://about.me/raulkripalani

<http://twitter.com/fusenews>

On 31 July 2012 17:12, rich_g <ri...@citi.com> wrote:

> Hi all
> I want to make a timer that polls a Mongo collection to get data with an id
> > variable set at runtime.
>
> I am able to get a timer working using but don't know how to set a query
> filter
>
> from("timer://myTimer?period=30000")
>
>
> .to("mongodb:myDb?database=test&collection=test&operation=findAll&dynamicity=true")
>        .to("stream:out");
> but don't know
>
>
> And using the unit tests for camel-mongo I am able to query using the code
> below to get the filtered set.
>
> DBObject query =
> BasicDBObjectBuilder.start().push("_id").add("$gte",12).get();
> Object result = template.requestBody("direct:findAll", query);
>
> ....
>
>   from("direct:findAll")
>                     .to("mongodb:myDb?database
> test&collection=test&operation=findAll&dynamicity=true")
>                     .to("mock:resultFindAll");
>
>
> Can anyone give me some advice on how to combine the 2?
>
> Thanks
>
> Rich
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Using-timer-and-MongoDb-queries-tp5716634.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Using timer and MongoDb queries

Posted by rich_g <ri...@citi.com>.
Thanks guys,
That helps a lot.




--
View this message in context: http://camel.465427.n5.nabble.com/Using-timer-and-MongoDb-queries-tp5716634p5716984.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Using timer and MongoDb queries

Posted by "Gibson, Richard " <ri...@citi.com>.
Thanks Raul,

Knew there had to be some way of doing this but new to Camel

-----Original Message-----
From: Raul Kripalani [mailto:raul@fusesource.com]
Sent: 08 August 2012 13:31
To: users@camel.apache.org
Subject: Re: Using timer and MongoDb queries

Hi Rich,

All you need to do is specify the query object as the body of the IN
message.

Ultimately, the query object should be a DBObject (i.e. a JSON object), but
the good news is that camel-mongodb supports automatic type conversions
from Strings and HashMaps!

So you could do the following:

from("timer://myTimer?period=30000")
    .setBody().constant("{\"foo\": \"bar\"}")

.to("mongodb:myDb?database=test&collection=test&operation=findAll&dynamicity=true")
    .to("stream:out");

This will return all objects that contain a field "foo" whose value is
"bar". Remember to escape inner quotes in the JSON object.

And you are right, this use case doesn't appear in the component's
documentation. I'll update straightaway.

Hope that helps.

P.S.: No need to use custom processors as Sam described. As of Camel 2.10,
there's a camel-mongodb component to interact with MongoDB databases
directly from your routes.

Thanks,

*Raúl Kripalani*
*Principal Consultant | FuseSource Corp.
raul@fusesource.com | fusesource.com <http://www.fusesource.com/>
skype: raul.fuse | twitter: @raulvk <http://twitter.com/raulvk>,
@fusenews<http://twitter.com/fusenews>
*
blog: F3 - Flashes From the
Field<http://blog.raulkr.net/?utm_source=fusesourceemail&utm_medium=email&utm_campaign=fusesourcemail>
aboutme: http://about.me/raulkripalani

<http://twitter.com/fusenews>

On 31 July 2012 17:12, rich_g <ri...@citi.com> wrote:

> Hi all
> I want to make a timer that polls a Mongo collection to get data with an id
> > variable set at runtime.
>
> I am able to get a timer working using but don't know how to set a query
> filter
>
> from("timer://myTimer?period=30000")
>
>
> .to("mongodb:myDb?database=test&collection=test&operation=findAll&dynamicity=true")
>        .to("stream:out");
> but don't know
>
>
> And using the unit tests for camel-mongo I am able to query using the code
> below to get the filtered set.
>
> DBObject query =
> BasicDBObjectBuilder.start().push("_id").add("$gte",12).get();
> Object result = template.requestBody("direct:findAll", query);
>
> ....
>
>   from("direct:findAll")
>                     .to("mongodb:myDb?database
> test&collection=test&operation=findAll&dynamicity=true")
>                     .to("mock:resultFindAll");
>
>
> Can anyone give me some advice on how to combine the 2?
>
> Thanks
>
> Rich
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Using-timer-and-MongoDb-queries-tp5716634.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>