spring-projects / spring-projects/spring-data-mongodb
MongoConverter mapkeydotreplacement does not work with nested documents [DATAMONGO-2636]
@christophstrobl is already working on this.
Since Dec 30, 2020.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Satish opened DATAMONGO-2636 and commented
Trying to insert a json into mongodb, however the json has nested json objects which has a dot(.) in the key.
Creating a MappingMongoConverter and providing a replacement does not work for nested documents
Example:
val converter = new MappingMongoConverter(new DefaultDbRefResolver(dbFactory), new MongoMappingContext)
converter.setMapKeyDotReplacement("-")
val mongo = new MongoTemplate(dbFactory,converter)
var jsonmessage = "\{\"timestamp\": 1594313810768, \"status\": \"SUCCESS\", \"service.config\": {\"service.code\": \"SA30\"}}"
val doc = Document.parse(jsonmessage)
mongo.insert(doc, ""test_doc")
The above fails as it only changes dot on the top level (service.config) but does not replace at the nested level(service.code).
However parsing into a BasicDBObject seems to work
This works:
val doc = BasicDBObject.parse(jsonmessage)
mongo.insert(doc, ""test_doc")
It seems like Document is treated as a simple type and hence does not iterate into the nested documents.
Is there any alternative for this to work with Document?
No further details from DATAMONGO-2636
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.