How to configure mongo converter in spring to enco

2019-07-23 18:14发布

问题:

In my spring project i have to save a map in mongo db ,Which is simple and i have done it. But then there a problem occurred while saving this map in mongo db with a key as as string like "N. Delhi" . I tried to figure out and found that in mongo db it is not allowed to save a map key with "." (dot) int because dot is have special meaning in mongo db.

After few search i found that there is class in spring mongo driver named as MonoMappingConverter which have a method setMapKeyDotReplacement which could be used to encode all dots in mongo document before it save in mongodb and decode it back to dot while fetching. I tried but didn't found right xml configuration of this converter with mongo template .

Can some one please let me know how correctly i could configure this converter in project or any other simplest way to save a map with dots in its keys in mongo.