Add type arguments support to MongoDatabase#getCollection

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: POJO
    • None
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      MongoDatabase#getCollection currently only supports simple Class<T> to get MongoCollection<T>.
      However, with more complex setups, where type arguments are used, it is not possible to get the correct document type for the MongoCollection.

      For example, ideally, I would want to have MongoCollection<ProtoHolder<MyType>>, but it's not possible.
      With current limitations I need to use MongoCollection<BsonDocument> and then manually get the codec and decode every collection's entry, in my example like that:

      //noinspection unchecked,rawtypes
      Codec<ProtoHolder<MyType>> codec = (Codec) database.getCodecRegistry().get(ProtoHolder.class, List.of(MyType.class));
      
      return collection.find().map(document -> codec.decode(
              document.asBsonReader(), DecoderContext.builder().build()
      )); 

              Assignee:
              Slav Babanin
              Reporter:
              MichaƂ Telenga
              None
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: