Adding data to a graph in DataStax Studio

To add data to a graph from a cell in your notebook:

  1. Add four more vertices and two other edges:

    user = graph.addVertex(label, 'user', 'id', 2, 'name', 'Jay Quest', 'role', 'customer')
    product = graph.addVertex(label, 'product', 'id', 3, 'name', 'digital camera')
    user.addEdge('bought', product)
    
    user = graph.addVertex(label, 'user', 'id', 3, 'name', 'Bartholmew Hicks', 'role', 'employee')
    product = graph.addVertex(label, 'product', 'id', 4, 'name', 'eraser')
    schema.edgeLabel('manufactured').create()
    user.addEdge('manufactured', product)
    
    g.V()
    gs4vertices2edges
    Graph studio instance with four vertices and two edges
  2. Create an edge between two existing vertices:

    1. Add this code to a new Gremlin cell:

      user = g.V().has('user', 'name', 'Jo Dowe').next()
      product = g.V().has('product', 'name', 'eraser').next()
      user.addEdge('bought', product)
      
      g.V()
    2. Switch the cell to display a graph.

    3. Select the Jo Dowe user vertex.

      gsDoweEraser
      gsDoweEraser

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com