1

Consider the following query where some items are merged into the database and where one of the properties is converted into a relationship (all in one go):

# items=[{id: 'a', experiment: 1}, {id: 'b'}]
UNWIND $items AS item MERGE (x:Item { id: item.id })
SET x = item, x.experiment = null
WITH x, item.experiment as experiment WHERE NOT experiment IS NULL
CALL {
  WITH x, experiment
  MERGE (x)-[:IN_EXPERIMENT]->(e:Experiment { name: experiment })
}
RETURN x.id

This returns:

╒══════╕
│"x.id"│
╞══════╡
│"a"   │
└──────┘

This is due to the fact that WHERE filters the original items from UNWIND . What would be the most efficient way to return all items from the original list?:

╒═════════╕
│"item.id"│
╞═════════╡
│"a"      │
├─────────┤
│"b"      │
└─────────┘

The idea is to do not query again the whole database with another MERGE/MATCH because the data is already in memory. The best I can think on is to add another UNWIND using the original list, but there might be a better way I cannot think off.

...
WITH x, item.experiment as experiment WHERE NOT experiment IS NULL
CALL {...}
UNWIND $items AS item RETURN item.id
Taja Jan
  • 942
  • 1
  • 1
  • 11
BorjaEst
  • 390
  • 2
  • 11

0 Answers0