Help using apoc.coll.max

(Paul Drangeid) #1

Using Neo4J 3.5.3, and latest APOC.

Trying to return the "latest" date among 3 date properties (in epoch ms format). I collect the properties into a collection variable, and then attempt apoc.coll.max as shown here:

MATCH (d:Mwpdevice)--(:Mwpactivestatus {state:1}) where not exists(d.deletedon)
WITH *,collect([d.lastboot,d.createdon,d.ipchanged]) as dates
WITH *,apoc.coll.max(dates) as latestdate
return latestdate

But the results for "latestdate" are just the collection:
Why is this not returning the single largest value of the collection? I tried tointeger() when adding to the collection, but that made no difference.

What am I doing wrong here?

(Michael Hunger) #2

Beause you have a double nested collection.

collect([...]) creates a list of lists.

You should use apoc.coll.max(apoc.coll.flatten(dates))