I am trying to fetch a parent node and its related nodes by id. It works fine but when I try to filter the related nodes by certain criteria the parent node itself is not returned when the related nodes do not pass the given criteria or filters
MATCH (obj{CId:"AT11"})
OPTIONAL MATCH (obj)-[r]->(related)
WHERE related.Created >= "2024-03-03" AND related.Created <= "2024-03-06"
WITH obj,related
WHERE related.CId CONTAINS 'AT'
RETURN obj, related
I expect obj to be returned even if related is null. In my case both return null even though obj exists
I tried removing some of the filters and I realized when using only one where clause works fine but using multiple where clause seems to be the issue.
To always return
obj, all therelatedfiltering should be done in theWHEREclause of theOPTIONAL MATCH:Note: this query also uses chained comparison for the
Createddate.Optional filtering
If you pass parameters for the
objCId ($obj_cid) and therelatedfiltering ($date_rangeand$rel_cid_substr), and the filtering parameters are optional (that is, can haveNULLvalues), you can use the following: