Azure Cosmos Graph DB - Create Vertices and Edges using Gremlin API
(Redirected from Graph DB - Create Vertices and Edges)
Jump to navigation
Jump to search
- Setup Gremlin connectivity - remote-secure.yaml
hosts: [cosmosdb-graph.gremlin.cosmosdb.azure.com]
port: 443
username: /dbs/sampledb/colls/samplegraph
password: 1234567890123456789012344444555555555555555555g==
connectionPool: {
enableSsl: true}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}
- Start
bin/gremlin.bat :remote console
- Graph creation and query
// Create Vertices
:> g.addV('person').property('firstName', 'Thomas').property('lastName', 'Andersen').property('age', 44).property('userid', 1)
:> g.addV('person').property('firstName', 'Mary Kay').property('lastName', 'Andersen').property('age', 39).property('userid', 2)
:> g.addV('person').property('firstName', 'Robin').property('lastName', 'Wakefield').property('userid', 3)
:> g.addV('person').property('firstName', 'Ben').property('lastName', 'Miller').property('userid', 4)
:> g.addV('person').property('firstName', 'Jack').property('lastName', 'Connor').property('userid', 5)
// Thomas > Mary Kay
:> g.V().hasLabel('person').has('firstName', 'Thomas').addE('knows').to(g.V().hasLabel('person').has('firstName', 'Mary Kay'))
// Thomas > Robin
:> g.V().hasLabel('person').has('firstName', 'Thomas').addE('knows').to(g.V().hasLabel('person').has('firstName', 'Robin'))
// Robin > Ben
:> g.V().hasLabel('person').has('firstName', 'Robin').addE('knows').to(g.V().hasLabel('person').has('firstName', 'Ben'))