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

MongoCollection.listIndexes() fails when there is an index with partialFilterExpression that contains DBRef

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.11.0
    • Component/s: Codecs
    • Labels:
      None

      How to re-produce:

      First, create an index that has partialFilterExpression which contains DBRef, such as:

      db.user.createIndex({"organisation": 1, "email": 1}, {name: "org-uniq-email", unique: true, partialFilterExpression: {"organisation": DBRef("organisation", ObjectId("59ce08baf264b906810fe8c5")), "email": {$exists: true}}})
      

      Then try to list and print those indexes:

      public static void main(String[] args) {
      	try (MongoClient mongo = new MongoClient("localhost")) {
      		MongoDatabase db = mongo.getDatabase("test");
      		MongoCollection<Document> col = db.getCollection("user");
      		col.listIndexes().spliterator().forEachRemaining(index -> System.out.println(index.toJson()));
      	}
      }

      This results in exception:

      Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.DBRef.
      	at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
      	at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
      	at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
      	at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:184)
      	at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:199)
      	at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:182)
      	at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:199)
      	at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:141)
      	at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)
      	at org.bson.Document.toJson(Document.java:439)
      	at org.bson.Document.toJson(Document.java:412)
      	at org.bson.Document.toJson(Document.java:399)

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            miika.vesti@trivore.com Miika Vesti
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: