I am trying to insert the Large JSON document in the Couchbase. I have inserted the document like below.
Bucket bucket = cluster.openBucket("default");
String jsondoc = "{{
"exams": {
"exam1": {
"year": {
"math": {
"questions": [
{
"question_text": "first question",
"options": [
"option1",
"option2",
"option3",
"option4",
"option5"
],
"answer": 1,
"explaination": "explain the answer"
},
{
"question_text": "second question",
"options": [
"option1",
"option2",
"option3",
"option4",
"option5"
],
"answer": 1,
"explaination": "explain the answer"
},
{
"question_text": "third question",
"options": [
"option1",
"option2",
"option3",
"option4",
"option5"
],
"answer": 1,
"explaination": "explain the answer"
}
]
},
"english": {same structure as above}
},
"1961": {}
},
"exam2": {},
"exam3": {},
"exam4": {}
}
}}";
JSONObject jsonObj = new JSONObject();
jsonObj.put("examinfo", jsondoc); // Entire JSON Document(String jsondoc) is keeping as value for the JSON Object.
bucket.upsert(JSONDocument.create("exam", jsonObj));
After Inserting the document like above, I want to retrieve individual nested nodes(ex: questions) while fetching.
How to get Particular Node from the above inserted document. I have used array subscripting(exams.exam1.year.math.questions) but It gives empty as a result.
Note: I am using Couchbase 4.0 community Edition, So I can not use subdoc feature intriduced in 4.5.
Could some body Please tell me what I am doing wrong here or Is my insertion is not proper?