Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5600

Reactive API for creating a capped collection does not publish an error if collection already exists

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 5.1.4
    • Component/s: None
    • None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      Driver version 4.11.x failed the reactive stream with a `MongoCommandException` when creating a collection and getting a Publisher as response.

       

      Driver version 5.1.x does neither publish a success (null void) nor an error to the stream it seems.

      I figured out that when creating a non-capped collection, the MongoCommandException is still emitted into the stream, so this seems to have something to do with capped collections (or max documents 1).

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      With Apache Pekko as reactive API wrapper:

      final CreateCollectionOptions collectionOptions = new CreateCollectionOptions().capped(true).sizeInBytes(cappedCollectionSizeInBytes).maxDocuments(1);
      
      Source.lazySource(
                      () -> Source.fromPublisher(database.createCollection("foo", collectionOptions)))
                      .mapMaterializedValue(whatever -> NotUsed.getInstance())
                      .map(nullValue -> Done.done())
                      .withAttributes(Attributes.inputBuffer(1, 1))
                      .recoverWithRetries(1, new PFBuilder<Throwable, Source<Done, NotUsed>>()
                              .match(MongoCommandException.class,                                 error.getErrorCode() == COLLECTION_ALREADY_EXISTS_ERROR_CODE,
                                      error -> Source.single(Done.done()))
                              .build()); 

      In the example, the lambda
      error -> Source.single(Done.done()))
      is never invoked. 

      When omitting the capped collection options, it is invoked when the collection already exists.

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            maxim.katcharov@mongodb.com Maxim Katcharov
            Reporter:
            thomas.jaeckle@beyonnex.io Thomas Jäckle
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: