1

Mongo java driver is not able to handle Latin characters. When I inserted "quantità" through mongo java driver to mongodb, it gets stored as "quantitÃ". However when I inserted it through mongod console then it is storing it correctly. Also, When I printed the string before insert in my java program then it was displaying correctly. But it stores incorrectly in mongodb. It look like this is the problem in mongo java driver.

Code used

try {
        Document productTemplateDocument = new Document();
        productTemplateDocument.append("fieldName", "Quantità");
        String templateCollectionName = CommonUtils.getProductTemplateCollectionName(productType);
        mongoClient = ConnectionManagerFactory.getMongoClient();
        MongoDatabase mongoDb = mongoClient.getDatabase(DatabaseConstants.DATABASE_NAME);
        log.debug("Calling database insert");
        MongoCollection<Document> mongoCollection = mongoDb.getCollection(templateCollectionName);

        if(mongoCollection==null) {
            mongoDb.createCollection(templateCollectionName);
            mongoCollection = mongoDb.getCollection(templateCollectionName);    
        }
        ///MongoCollection<Document> mongoCollection = DBCollectionManagerFactory.getOrCreateCollection(mongoDb, templateCollectionName);
        log.info("productTemplateModel "+productTemplateModel);

        mongoCollection.insertOne(productTemplateModel);
}

Could anyone please help me to resolve this.

Thank you so much in advance.

  • I think you need to show us your code where you are sending the string through mongo java driver to mongodb – Stephen C Mar 21 '16 at 16:30

0 Answers0