Namani Supriya
Namani Supriya

Reputation: 71

Gremlin Order by latest Date

I added vertices with createDate as a property. I want to retrieve the latest created vertex using createDate property.

How can I retrieve this. Please help me with this.

Upvotes: 1

Views: 6517

Answers (1)

stephen mallette
stephen mallette

Reputation: 46226

Just order() your vertices in descending order by the createDate and grab the first one:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.V().order().by('createDate', desc).limit(1)
==>v[2]
gremlin> g.V().order().by('createDate', desc).limit(1).values('createDate')
==>22-OCT-2019

Upvotes: 7

Related Questions