从neo4j中的列表中删除空值

时间:2018-09-28 11:22:57

标签: neo4j cypher

我有下一个查询:

MATCH (dd:Dod)
        WHERE dd.name contains 'cu'
        WITH collect({displayName:dd.displayName, type: 'Dod',
             link: {name: dd.name},
             date: apoc.date.format(coalesce(dd.modifiedAt, dd.createdAt))}) as rows1

        OPTIONAL MATCH (dn:Dod)<-[:BELONGS_TO]-(nn:Namespace)
        WHERE nn.name contains 'cu'
        WITH 
        rows1 + collect({displayName:nn.displayName, type: 'namespace',
             link:  {name: nn.name, DodName:dn.name},
             date: apoc.date.format(coalesce(nn.modifiedAt, nn.createdAt))}) as rows2

        OPTIONAL MATCH (de:Dod)<-[:BELONGS_TO]-(ne:Namespace)<-[:BELONGS_TO]-(ee:Edod)
        WHERE ee.name contains 'cu'
        WITH rows2 + collect({displayName:ee.displayName, type: 'Edod',
             link:  {name: ee.name, DodName: de.name, namespaceName: ne.name},
             date: apoc.date.format(coalesce(ee.modifiedAt, ee.createdAt))}) as rows3

UNWIND rows3 as row
RETURN row
ORDER BY row.date DESC
SKIP 0
LIMIT 10;

在结果中,我得到了所需的值+按组为空(如果未找到Dod /命名空间/ Edod的系统结果) 我需要从row3删除此空值。 我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以在WHERE语句之前添加RETURN子句:

UNWIND rows3 as row
WHERE row IS NOT NULL
RETURN row
ORDER BY row.date DESC
SKIP 0
LIMIT 10;