cts 查询以从 Marklogic 暂存中的 json 文档的字段中查找唯一值
cts query to find unique values from a field from json document in Marklogic staging
我正在尝试编写一个 JavaScript cts 查询,以仅从基于另一个键的 JSON 文档中的一个键查询唯一值。即类似于这样的查询:select distinct(name) from data-hub-staging where source='source1'
{
"source": "source1",
"name": "John",
"DOB": "1-01-1990",
"load_date": "2021-10-23 10:23:55"
},
{
"source": "source1",
"name": "John",
"DOB": "1-01-1990",
"load_date": "2021-10-24 10:23:55"
},
{
"source": "source1",
"name": "Mark",
"DOB": "1-01-1990",
"load_date": "2021-10-24 10:23:55"
}
我一直在尝试下面的查询,但它 returns 所有字段。我只想要唯一的 name 字段。
const query = cts.jsonPropertyValueQuery(
"source",
"source1");
[...new Set (cts.search(query)
.toArray()
.map(doc => doc.root.name).sort())]
Current result: [John,John,Mark]
Expected result: [John,Mark]
name
值未被集合删除重复,因为它们是 text()
节点。您需要获取 .valueOf()
那些文本节点,然后字符串将被去重。
const query = cts.jsonPropertyValueQuery(
"source",
"source1");
[...new Set (cts.search(query)
.toArray()
.map(doc => doc.root.name.valueOf()).sort())]
我正在尝试编写一个 JavaScript cts 查询,以仅从基于另一个键的 JSON 文档中的一个键查询唯一值。即类似于这样的查询:select distinct(name) from data-hub-staging where source='source1'
{
"source": "source1",
"name": "John",
"DOB": "1-01-1990",
"load_date": "2021-10-23 10:23:55"
},
{
"source": "source1",
"name": "John",
"DOB": "1-01-1990",
"load_date": "2021-10-24 10:23:55"
},
{
"source": "source1",
"name": "Mark",
"DOB": "1-01-1990",
"load_date": "2021-10-24 10:23:55"
}
我一直在尝试下面的查询,但它 returns 所有字段。我只想要唯一的 name 字段。
const query = cts.jsonPropertyValueQuery(
"source",
"source1");
[...new Set (cts.search(query)
.toArray()
.map(doc => doc.root.name).sort())]
Current result: [John,John,Mark]
Expected result: [John,Mark]
name
值未被集合删除重复,因为它们是 text()
节点。您需要获取 .valueOf()
那些文本节点,然后字符串将被去重。
const query = cts.jsonPropertyValueQuery(
"source",
"source1");
[...new Set (cts.search(query)
.toArray()
.map(doc => doc.root.name.valueOf()).sort())]