Skip to content

Incorrect code snippet for change streams documentation #4376

Closed
@sergey-morenets

Description

@sergey-morenets

Hi

Here's code snippet from official documentation(https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#change-streams):


MessageListenerContainer container = new DefaultMessageListenerContainer(template);
container.start();                                                                                        

MessageListener<ChangeStreamDocument<Document>, User> listener = System.out::println;                     
ChangeStreamRequestOptions options = **new ChangeStreamRequestOptions("user", ChangeStreamOptions.empty());**

However current Spring Data MongoDB version (4.0.5) doesn't contain ChangeStreamRequestOptions class where constructor accepts two parameters, only three arguments:

		public ChangeStreamRequestOptions(@Nullable String databaseName, @Nullable String collectionName,
				ChangeStreamOptions options) {
			this(databaseName, collectionName, null, options);
		}

public ChangeStreamRequestOptions(@Nullable String databaseName, @Nullable String collectionName,
				@Nullable Duration maxAwaitTime, ChangeStreamOptions options) {

			Assert.notNull(options, "Options must not be null");

			this.collectionName = collectionName;
			this.databaseName = databaseName;
			this.maxAwaitTime = maxAwaitTime;
			this.options = options;
		}

The code snippet below doesn't compile:

Subscription subscription = container.register(new ChangeStreamRequest<>(listener, options), User.class);

with error:

Cannot infer type arguments for ChangeStreamRequest<>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions