You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Dario Nuevo (Jira)" <ji...@apache.org> on 2021/01/12 10:56:00 UTC
[jira] [Created] (CAMEL-16024) [camel-mongodb] ChangeStreams
Consumer cannot handle string based _id
Dario Nuevo created CAMEL-16024:
-----------------------------------
Summary: [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: Bug
Components: camel-mongodb
Reporter: Dario Nuevo
Fix For: 3.7.0
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 not 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.3.4#803005)