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

Id property mapping is not applied to index selection

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Won't Do
    • Icon: Unknown Unknown
    • None
    • 4.9.1
    • None
    • None
    • 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?

    Description

      Summary

      Id property mapping is not applied to index selection resulting in the query performing a collection scan instead of using the index.

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

      mongo-driver-sync-4.9.1

      Atlas 5.0.19, Standalone 5.0.3

      How to Reproduce

      Java classes:

      public class SomeEntity {    @MongoId(FieldType.IMPLICIT)    private Long id; // We use @Id String but that is irrelevant for the example
          private SomeRef someRef;
      }
      public class SomeRef {
          @MongoId(FieldType.IMPLICIT)
          private String id;
          private String name;
      }

      Some data:

      { "_id": 123, { "_id': "a", "name": "Apple" } }{ "_id": 456, { "_id': "b", "name": "Banana" } }

      Add index:

      db.someEntity.createIndex({ "someRef._id": 1}, {background: true});
      creates an index named: someRef._id_1

      Perform a query:

      mongoTemplate.find(new Query(Criteria.where("someRef.id").is("a")), someEntity.class)

      The logged query is 

      { "someRef.id": "a" }
      

      it returns record 123 but it results in a collection scan because it can't find an index for "someRef.id". The driver mapped the "someRef.id" to "someRef._id" for the find but not for the index selection.

      Additional Background

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

      Attachments

        Activity

          People

            Unassigned Unassigned
            nathan.niesen@datasite.com Nathan Niesen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: