2015-10-13 42 views
0

我想使用COLLECT函数来构造使用文字地图语法的对象的数组。但是,如果我使用的属性没有返回值,我宁愿返回一个空数组,而不是数组的对象元素为其属性保留空值。我如何忽略这些值并返回[]而不是这个?Cypher查询:如何ingnore文字地图语法当值为空

[ 
    { 
     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; 

我想有[]的数值为instantiationset,而不是这样的:

[ 
    { 
     "container": null, 
     "target": null 
    } 
] 

回答

1

该查询应该工作。

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;