I have documents like below in a collection named event in mongoDB
{
"name": "pick",
"message": {
"word": "seven",
"sequenceNumber": 34
}
}
which existed before I developed my Spring Boot application to access it. Now I have a java object Event.java to access the above collection.
public class Event{
private String name;
private JSONObject messgae;
// getters setters costructors
}
In the document, the message could be any json. So defining a class for message does not make any sense.
I have tried using mongoOperations, mongoTemplate and mongoRepository but I am not able to access the the document and change the value and store it again. The problems I face are,
- I could not use
JSONObjectfor message becausemongoOperationshas no support - I could not use
Stringformessagebecause when I save the object again it gets serialized like"message":"{\"word ...
Is there any way I can access, modify and store the data via spring boot application?