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); } }
- duplicates
-
JAVA-2810 Allow dots and $ in field names
- Closed
- related to
-
SERVER-30575 Please add escaping convention for dot and dollar signs!
- Backlog