cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Help using apoc.coll.max

pdrangeid
Graph Voyager

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:
[1536097126127,1535148519263,1535148557860]
[null,1535148519137,1535148557750]
...
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?

1 REPLY 1

Beause you have a double nested collection.

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

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

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online