我正在尝试使用COLLECT函数来构造使用文字映射语法的对象数组。但是,如果我使用的属性没有返回值,我宁愿返回一个空数组,而不是数组的对象元素保留其属性的空值。如何忽略这些值并返回[]而不是这个?
[
{
property_a: null,
property_b: null
}
]
这是我尝试过的密码查询:
MATCH (n)-[r]-()
WHERE n.id={_nodeid}
WITH n
OPTIONAL MATCH (n)-[instantiationlist:INSTANTIATES]->(target)
WITH n, COLLECT({
container : instantiationlist.container,
target : target.id
}) AS instantiationset
RETURN n.id AS id,
n.name AS name,
n.color AS color,
n.background AS background,
LABELS(n)[0] AS type,
instantiationset AS instantiations;
我正在尝试为实例化集设置值[]而不是:
[
{
"container": null,
"target": null
}
]
答案 0 :(得分:2)
此查询应该有效。
OPTIONAL MATCH (n {id: 123})-[ilist:INSTANTIATES]->(target)
WITH n, COLLECT(
CASE
WHEN ilist.container IS NULL THEN NULL
ELSE { container : ilist.container, target : target.id } END
) AS iset
RETURN n.id AS id, n.name AS name, n.color AS color, n.background AS background, LABELS(n)[0] AS type, iset AS instantiations;