spring-projects / spring-projects/spring-data-mongodb

No error logged or thrown using change stream and incompatible featureCompatibilityVersion [DATAMONGO-2212]

Open
#3,053 0 comments 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Dec 30, 2020.

type: bug
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

JeremyTwiggs opened DATAMONGO-2212 and commented

When using ReactiveMongoTemplate to consume a change stream, no errors are logged and no exceptions are thrown when the featureCompatibilityVersion required by my app is incompatible with that of the actual database.

Switching on debug logging reveals the following:

com.mongodb.MongoCommandException: Command failed with error 72 (InvalidOptions): 'The featureCompatibilityVersion must be 3.6 to use the $changeStream stage. See http://dochub.mongodb.org/core/3.6-feature-compatibility.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The featureCompatibilityVersion must be 3.6 to use the $changeStream stage. See http://dochub.mongodb.org/core/3.6-feature-compatibility.", "code" : 72, "codeName" : "InvalidOptions" }com.mongodb.MongoCommandException: Command failed with error 72 (InvalidOptions): 'The featureCompatibilityVersion must be 3.6 to use the $changeStream stage. See http://dochub.mongodb.org/core/3.6-feature-compatibility.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The featureCompatibilityVersion must be 3.6 to use the $changeStream stage. See http://dochub.mongodb.org/core/3.6-feature-compatibility.", "code" : 72, "codeName" : "InvalidOptions" } at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179) at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:370) at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:356) at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:651) at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:618) at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:494) at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:491) at com.mongodb.internal.connection.AsynchronousSocketChannelStream$BasicCompletionHandler.completed(AsynchronousSocketChannelStream.java:237) at com.mongodb.internal.connection.AsynchronousSocketChannelStream$BasicCompletionHandler.completed(AsynchronousSocketChannelStream.java:220) 

In my case, the v3.6.6 MongoDB had been upgraded from 3.4 and featureCompatibilityVersion was still showing as 3.4.

Setting featureCompatibilityVersion`` to 3.6 solved the issue.

My code is pretty simple and does not use an ErrorHandler

 

public void setupChangeStreamListener() {
    reactiveTemplate.changeStream(
        "myCollection", 
        ChangeStreamOptions
            .builder()
            .filter(newAggregation(match(where("operationType").in(OperationType.INSERT.getValue(), OperationType.UPDATE.getValue()))))
            .build(),
            MyCollection.class)
        .doOnEach(this::consumer)
        .subscribe();
}

private void consumer(Signal<ChangeStreamEvent<MyCollection>> signal) {
    ChangeStreamEvent<MyCollection> event = signal.get();
    log.info(event.toString());
} 

NB: I am using spring-boot 2.1.3 with spring-boot-starter-data-mongodb-reactive 2.1.2

 


Issue Links:

  • DATAMONGO-1876 Provide more user friendly error messages based on MongoDB error codes and context of use
    ("supersedes")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.