【发布时间】:2022-01-16 21:59:28
【问题描述】:
我的集合中有一个格式如下的 JSON 文档:
{
"id":{
"idValue":[
{"value1": ["a"],
"value2":["b"]
},
{"value1": ["a"],
"value2":["c"]
}
]
}
}
我需要获取具有 "value1"=="a" 和 "value2"=="b" 的 JSON 文档并仅返回该实例。
我在我的代码中使用了 jsearch,如下所示
const jsearch = require('/MarkLogic/jsearch.sjs');
var prodct = jsearch.collections(["idCollection"]);
function mapper(result) {
return {
value1: result.document.id["idValue"],
value2: result.document.id["idValue"]
};
}
var output=
prodct.documents()
.where(cts.andQuery([cts.jsonPropertyWordQuery("value1","a"),cts.jsonPropertyWordQuery("value2","b")]))
.slice(0,10)
.map(mapper)
.result();
output.results
如何访问映射器函数中的值数组?
【问题讨论】:
标签: javascript arrays json object marklogic-9