I'm trying to read a single JSON node from MongoDb via my Springboot project.
here is the sample JSON saved in Mongo:
"a": {
"b": {
"c": {
"d": "value1",
"e": "value2"
}
}
}
I tried:
public String get() {
BasicDBObject query = BasicDBObject.parse("{\"a.b.c.d\": \"value1\"}");
FindIterable<Document> dumps = mongoOperations.getCollection("data").find(query);
return dumps.first().toJson();
}
response I got:
{
"_id": {
"$oid": "5e8aa42602ef9f05bf35ff59"
},
"a": {
"b": {
"c": {
"d": "value1",
"e": "value2"
}
}
}
}
but I only need the node a.b.c.d, I know I can do it in java after reading the whole JSON. But my intention is to read only the needed part.
Expected Output:
{
"a": {
"b": {
"c": {
"d": "value1"
}
}
}
}
Also please note that I'll be saving JSONs with random schema so no POJOs associated with it. It would be really helpful if somebody can guide me on this.