Skip to content

JAVA-6258 Support arbitrary aggregate command options in ChangeStreamIterable/Publisher, AggregateIterable/Publisher - #2091

Draft
stIncMale wants to merge 11 commits into
mongodb:mainfrom
stIncMale:JAVA-6258
Draft

stIncMale wants to merge 11 commits into
mongodb:mainfrom
stIncMale:JAVA-6258

Conversation

@stIncMale

@stIncMale stIncMale commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

…tests

Also move the sync & reactive test from `AbstractChangeSteamFunctionalTest` to `ChangeStreamProseTest`. This effectively matches the instructions that were left in `AbstractChangeSteamFunctionalTest`.

JAVA-6350
…geStreamPublisher.withDocumentClass`

JAVA-6351

public final class ListCollectionNamesIterableTest {
public static final Set<String> EXPECTED_EXTRA_METHODS = singleton("authorizedCollections(boolean)");
public static final Set<String> EXPECTED_MISSING_METHODS = singleton("timeoutMode(com.mongodb.client.cursor.TimeoutMode)");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make EXPECTED_MISSING_METHODS empty if #2090 is merged before this PR.

Comment on lines +49 to +51
default Publisher<TResult> timeoutMode(TimeoutMode timeoutMode) {
throw fail();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method if #2090 is merged before this PR.

Comment on lines +41 to +43
default MongoIterable<TResult> timeoutMode(TimeoutMode timeoutMode) {
throw fail();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method if #2090 is merged before this PR.

@stIncMale
stIncMale force-pushed the JAVA-6258 branch 2 times, most recently from 9c18062 to e49875e Compare November 20, 2026 18:25
…ble API method

Test changes:
- It does not seem possible to test the changes via both AggregateIterableSpecification/ChangeStreamIterableSpecification and AggregatePublisherImplTest/ChangeStreamPublisherImplTest, so I added AggregateIterableIntegrationTest/AggregatePublisherIntegrationTest, ChangeStreamIterableIntegrationTest/ChangeStreamPublisherIntegrationTest
- Moved ChangeStreamProseTest.batchSizeWorksForWithDocumentClass to ChangeStreamIterableIntegrationTest/ChangeStreamPublisherIntegrationTest.batchSizeWorksForWithDocumentClass

JAVA-6258
* @see ChangeStreamOperation#FORBIDDEN_COMMAND_OPTIONS
*/
// When changing this set, remember to update the documentation of the affected API.
public static final Set<String> FORBIDDEN_COMMAND_OPTIONS = unmodifiableSet(

@stIncMale stIncMale Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a Predicate, the same applies to ChangeStreamOperation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To implement this as a predicate, one has to do either of the following:

  • still have a field that holds the set
  • use multiple equals(...) or... comparisons

I like neither more than the current code, so I decided not to do the proposed change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. @apmasell, thank you for the idea on how to write the predicate in a way I did not see.

}

@Override
public <TDocument> MongoIterable<TDocument> withDocumentClass(final Class<TDocument> clazz) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not implemented via MongoIterableImpl.map?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least one of the reasons we can't implement this method via MongoIterable.map is the following.

map converts TResult into U, where U for withDocumentClass would have been TDocument, and TResult would have been ChangeStreamDocument<...>. That means, to implement withDocumentClass via map, we need to provide a the mapper Function<ChangeStreamDocument<...>, TDocument>. This means, instead of decoding raw bytes into TDocument right away, we would have decoded them into ChangeStreamDocument, and then converted it into TDocument (by encoding back into bytes, and decoding into TDocument), which is more wasteful.

Maybe there are other reasons, but I am not experimenting with this to find them out.

.collect(toCollection(TreeSet::new));
}

public static String signature(final Method method) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Rename to "erased signature"
  • Document that return types are ignored, which allows for the related discrepancies to stay unnoticed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @see ChangeStreamOperation#FORBIDDEN_COMMAND_OPTIONS
*/
// When changing this set, remember to update the documentation of the affected API.
public static final Set<String> FORBIDDEN_COMMAND_OPTIONS = unmodifiableSet(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. @apmasell, thank you for the idea on how to write the predicate in a way I did not see.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant