You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2022/09/02 17:34:00 UTC
[jira] [Resolved] (CAMEL-16024) [camel-mongodb] ChangeStreams Consumer cannot handle string based _id
[ https://issues.apache.org/jira/browse/CAMEL-16024?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-16024.
---------------------------------
Resolution: Later
No response from user
> [camel-mongodb] ChangeStreams Consumer cannot handle string based _id
> ---------------------------------------------------------------------
>
> Key: CAMEL-16024
> URL: https://issues.apache.org/jira/browse/CAMEL-16024
> Project: Camel
> Issue Type: Improvement
> Components: camel-mongodb
> Affects Versions: 3.7.0
> Reporter: Dario Nuevo
> Assignee: Ramu
> Priority: Major
> Fix For: 3.x
>
>
> We're having quite a basic use case: Our documents in MongoDB have string based IDs (field _id) - as opposed to having ObjectId() instances. It seems, the current release of camel-mongodb cannot handle that.
> Having defined a route based on ChangeStreams like that:
> {code}
> from("mongodb:mongoConnection?database=db&consumerType=changeStreams&collection=coll")
> .routeId("changestream")
> .process("changeStreamProcessor")
> .to("stream:out");
> {code}
> When an event arrives on an object with a string based _id; I get this Exception:
> {code}
> Exception in thread "Camel (camel-1) thread #1 - mongodb://mongoConnection" org.bson.BsonInvalidOperationException: Value expected to be of type OBJECT_ID is of unexpected type STRING
> at org.bson.BsonValue.throwIfInvalidType(BsonValue.java:419)
> at org.bson.BsonValue.asObjectId(BsonValue.java:150)
> at org.bson.BsonDocument.getObjectId(BsonDocument.java:271)
> at org.apache.camel.component.mongodb.MongoDbChangeStreamsThread.doRun(MongoDbChangeStreamsThread.java:75)
> at org.apache.camel.component.mongodb.MongoAbstractConsumerThread.run(MongoAbstractConsumerThread.java:68)
> at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
> at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
> at java.base/java.lang.Thread.run(Thread.java:830)
> {code}
> So we basically have a problem here: https://github.com/apache/camel/blob/camel-3.7.0/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbChangeStreamsThread.java#L75
> So now the fix would be easy - check the type with _instanceof ObjectId_ and act accordingly - and i could also contribute that - but I'm not clear if that can succeed.
> As I see it, the _id is later set on the header as MongoDbConstants.MONGO_ID - which then also would be a string. IMHO that's totally fine, everybody knows what type their _id's have.
> How to resolve this? IMHO it's quite a normal use case to have non-ObjectId-IDs.. ;-)
> Thanks for any input
--
This message was sent by Atlassian Jira
(v8.20.10#820010)