What is the difference between next() and iterate() when working with gremlin? Why does next() return the added vertex when calling g.addV()
, but iterate() does not? When should I use next() and when should I use iterate()?
Asked
Active
Viewed 2,154 times
5

JTW
- 3,546
- 8
- 35
- 49
1 Answers
12
The answer is already in your question. You'll use .next()
, when you need the result (and you are expecting exactly one result), and you'll use .iterate()
, when you don't need the result (typically mutation queries, that add/change properties, edges and/or vertices).

Daniel Kuppitz
- 10,846
- 1
- 25
- 34
-
5It is also worth noting that if you expect more than one result, `.toList()` will return a list of all the results. – KOB Aug 04 '20 at 12:24