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

wrong dots validation in field-name mongo >=3.6

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.9.0
    • Fix Version/s: None
    • Component/s: BSON, Codecs
    • Labels:
      None
    • Environment:
      simple java project with local mongo 4.0.3

      Description

      According to this , dots are allowed in fields name starting from mongo 3.6.

      The default pojo codecs ([described here|http://mongodb.github.io/mongo-java-driver/3.9/driver/getting-started/quick-start-pojo/)] are using CollectibleDocumentFieldNameValidator that is doing this validation without checking the DB version.

       

      Simple code to demonstrate:

      public static void main(String[] args) {
        CodecRegistry pojoCodecRegistry = fromRegistries(MongoClient.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));
       
        MongoClientSettings settings = MongoClientSettings.builder()
            .codecRegistry(pojoCodecRegistry)
            .build();
       
        com.mongodb.client.MongoClient mongoClient = MongoClients.create(settings);
        MongoDatabase database = mongoClient.getDatabase("test");
        database = database.withCodecRegistry(pojoCodecRegistry);
        MongoCollection<FieldDotsTester> coll = database.getCollection("dots_test", FieldDotsTester.class);
        coll = coll.withCodecRegistry(pojoCodecRegistry);
       
        //This line fails
        coll.insertOne(new FieldDotsTester("d.t", "1"));
       
        if (!coll.find().first().data.keySet().iterator().next().equals("d.t")) {
          throw new RuntimeException();
        }
      }
      

      With Class:

      import java.util.HashMap;
      import java.util.Map;
       
      public class FieldDotsTester {
        public Map<String, String> data;
       
        public FieldDotsTester() {}
       
        public FieldDotsTester(String k, String v) {
          data = new HashMap<>();
          data.put(k, v);
        }
      }
      
      

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ozma Oz Madar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: