spring-projects / spring-projects/spring-data-mongodb
No error logged or thrown using change stream and incompatible featureCompatibilityVersion [DATAMONGO-2212]
@christophstrobl is already working on this.
Since Dec 30, 2020.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.