Given I have this sample BSON Document which I retrieved from Mongo DB.
{
"field1": "text1",
"field2": {
"field2Sub1": "text2"
},
"field3" : [
{
"field3Sub1": "text3",
"field3Sub2": "text4"
},
{
"field3Sub1": "text5",
"field3Sub2": "text6"
}
],
"field4": {
"field4Sub1": "text7",
"field4Sub2" : [
{
"field4Sub2Sub1": "text8",
"field4Sub2Sub2": "text9"
},
{
"field4Sub2Sub1": "text10",
"field4Sub2Sub2": "text11"
}
]
}
}
In Mongo DB if I want to search for a document that has a field of field4Sub2Sub2
that contains the value "text11"
.
I can just do this kind of search query:
{"field4.field4Sub2.field4Sub2Sub2": "text11"}
Alternatively, I can also search a document that has a field of field3Sub1
that contains the value text3
with this kind of search:
{"field3.field3Sub1": "text11"}
Given the object above, I converted this to a Java BSON Document. And, I would like to ask if there is a way in Java or a Java Library that can search through the internals of Document and give me the value of a particular field.
Using a dot annotated search string e.g.
"field3[0].field3Sub1"
or
"field4.field4Sub1"
or
"field4.field4Sub2[1].field4Sub2Sub2"
which will be returning the following values correspondingly:
text3
text7
text11
Thanks