[JAVA-3101] wrong dots validation in field-name mongo >=3.6 Created: 25/Nov/18  Updated: 20/Apr/20  Resolved: 25/Nov/18

Status: Closed
Project: Java Driver
Component/s: BSON, Codecs
Affects Version/s: 3.9.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Oz Madar Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

simple java project with local mongo 4.0.3


Issue Links:
Duplicate
duplicates JAVA-2810 Allow dots and $ in field names Closed
Related
related to SERVER-30575 Please add escaping convention for do... Backlog

 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);
  }
}

 



 Comments   
Comment by Jeffrey Yemin [ 25/Nov/18 ]

This has already been reported as JAVA-2810, so closing this as a duplicate.

Generated at Thu Feb 08 08:58:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.