Claus Ibsen created CAMEL-27937:
-----------------------------------

             Summary: camel-mongodb: tailable consumer options not validated, 
writeConcern handling, findDistinct on non-String fields, credentials not 
encoded
                 Key: CAMEL-27937
                 URL: https://issues.apache.org/jira/browse/CAMEL-27937
             Project: Camel
          Issue Type: Bug
          Components: camel-mongodb
            Reporter: Claus Ibsen
             Fix For: 4.25.0


Found while improving the option descriptions of camel-mongodb for CAMEL-23832 
(pull request https://github.com/apache/camel/pull/31191).
These are separate problems of the component; the descriptions change only 
documents the current behavior.

h4. 1. Tailable consumer options are not validated
{{MongoDbEndpoint.createConsumer}} calls validateConsumerOptions() before 
dbConsumerType is set, so the tailable checks never run: a tailable consumer 
without tailTrackIncreasingField starts, lastVal stays null and every new 
cursor reads the whole capped collection again; persistentTailTracking without 
persistentId is accepted. validateProducerOptions also checks dbConsumerType, 
which is always null there.
Proposed change: resolve dbConsumerType first, then validate.

h4. 2. writeConcern is applied inconsistently
{{MongoDbProducer.calculateCollection}} applies writeConcern only when no 
CamelMongoDbDatabase or CamelMongoDbCollection header is used. Without 
dynamicity, the default ACKNOWLEDGED (w unset) always replaces the write 
concern of the client, for example w=majority from connectionUriString or a 
MongoClient from the registry.
Proposed change: apply withWriteConcern in all branches, and only when 
writeConcern was set explicitly.

h4. 3. findDistinct fails on non-String fields
{{MongoDbProducer.createDoDistinct}} calls distinct(field, String.class); 
StringCodec only reads STRING and SYMBOL values, so findDistinct on a numeric 
or date field fails with a BSON decoding error.
Proposed change: decode as BsonValue or Object.

h4. 4. username and password are not encoded in the connection string
{{MongoDbEndpoint.createMongoClientSettings}} puts username and password into 
the mongodb:// string without percent-encoding, so a password containing @, :, 
/ or % breaks the connection string (SslAwareMongoClient does encode them).
Proposed change: URL-encode them (UTF-8), or use MongoCredential.

h4. 5. A fixed changeStreamToken wins over the token repository
{{ChangeStreamCommitManager.readResumeToken}}: when changeStreamToken and 
changeStreamTokenRepository are both set, the fixed token always wins, so each 
restart resumes from it instead of from the stored token.
Proposed change: use the stored token when there is one.

h4. 6. Smaller issues
{{MongoDbEndpoint.createIndex}}: collectionIndex creates one single-field index 
per JSON entry, never a compound index, and reads the entries into a HashMap 
(order lost); with dynamicity and a collection header, ensureIndex runs 
createIndex on every exchange. validateOutputType is never called. Labels: 
CamelMongoDbResultTotalSize is labelled findAll but set by findById and 
findOneByQuery; CamelMongoDbResultPageSize is also set by findDistinct and 
aggregate; CamelMongoDbAllowDiskUse is also used by findById and 
findOneByQuery; cursorRegenerationDelay applies only to the consumer; 
fullDocument, changeStreamToken and changeStreamTokenRepository only apply to 
changeStreams; outputType is labelled common but the consumer rejects it. 
tailTrackCollection and tailTrackField have no defaultValue in the metadata. 
The doc page still mentions the Mongo Java Driver 4.x and DBObject.


_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to