我正在尝试在 Couchbase 中插入大型 JSON 文档。我已插入如下文件。
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);
bucket.upsert(JSONDocument.create("exam", jsonObj));
像上面那样插入文档后,我想在获取时检索单个嵌套节点(例如:问题)。
我有以下查询: 1)我可以使用传统方法插入文档吗: String query = "upsert into default(KEY, VALUE) values(jsondoc)"; statement.executeUpdateQuery(查询); 或者我是否需要在每个 JSONObject 中单独插入上述嵌套节点才能正确获取嵌套节点?
2)如何使用 N1QLQueryResult 来获取每个 json 文档作为一行只获取所需的 json 信息