Hi Ben,
I think the approach you're using in your route is good. Camel mongodb
component is using a mongodb driver which should mimic what is expected by
the mongodb various operation. The only problem you can find with the
save() operation is how to identify your document and be able to either
insert or update the record [1]. You may include an _id field so you can
control the identity of your document instead of leaving it to the db.
Maybe in your case you can directly use the update operation with the
upsert flag as false [2].

Regards,
Pasquale.

[1]
https://docs.mongodb.com/manual/reference/method/db.collection.save/#insert
[2] https://camel.apache.org/components/3.4.x/mongodb-component.html#_update

On Mon, Jul 26, 2021 at 11:34 AM Ben Warrick <horseatingwe...@gmail.com>
wrote:

> I'm new to Camel. I really like it so far. However, there's a task I'm
> struggling with. The approaches I'm drifting toward are overly complicated,
> and I feel like there must be an easier, more Camel-intended way of doing
> this.
>
> I'm receiving json documents from an Artemis queue. I'm using a
> content based router, and for the type==partial, I need to replace a
> document in MongoDB with it. The content based router was easy enough to
> figure out. But I'm stuck figuring out how to remove the duccent
> document(s) in MongoDB before inserting the new one.
>
> I've experimented with a few approaches. I'd try to describe them, but I'm
> betting this is an easy question to answer... Here is my route
>
> from("jms:topic:orderbook.raw.feed")
> .choice()
> .when().jsonpath("$.[?(@.type=='partial')]")
> // Need to delete the current document(s) with {currency:"USD"}
> .to("mongodb:mongo?database=k2_dev&collection=orderbooks&operation=save");
>
>
> Thanks for any advice.
>

Reply via email to