2015-10-13 46 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;