1
votes

I'm following this tutorial:

https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-python.html

How can I add a node and then retrieve the same node?

from __future__  import print_function  # Python 2/3 compatibility

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()

remoteConn = DriverRemoteConnection('wss://your-neptune-endpoint:8182/gremlin','g')
g = graph.traversal().withRemote(remoteConn)

print(g.V().limit(2).toList())
remoteConn.close()

All the above right now is doing is retrieving 2 nodes right?

1
The question is not clear. Did you mange to connect to Neptune and run the query? If not, can you provide more information on the error message you receive.Kfir Dadosh

1 Answers

3
votes

If you want to add a vertex and then return the information about the vertex (assuming you did not provide your own ID) you can do something like

newId = g.addV("mylabel").id().next()