create
How to create a new graph.
Synopsis
system.graph('graph_name').create()
Description
Create a new graph. The
graph_name
specified is used to create two DSE
database keyspaces, graph_name
and graph_name_system
, and
can only contain alphanumeric and underscore characters.Important: Creating a
graph should include setting the replication factor for the graph and the graph_system. It can also include
other options.
Examples
Create a simple new graph.
system.graph('FridgeItems').create()The resulting list:
==>FridgeItems
is created with the
NetworkTopologyStrategy
class and replication factor based on the number
of datacenter nodes, since no options were specified.Create a simple new graph if it doesn't currently exist by modifying with
ifNotExists()
.
system.graph('FridgeItems').ifNotExists().create()The resulting list:
==>FridgeItems
An example that creates a graph on a cluster with two datacenters of 3
nodes:
system.graph('FridgeItems). replication("{'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 3 }"). systemReplication("{'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 3 }"). ifNotExists().create();The result:
==>null
shows that the graph was successfully created. The replication settings can be verified using the
cqlsh
tool, running the
CQL DESCRIBE KEYSPACE
command:
DESCRIBE KEYSPACE "FridgeItems";
DESCRIBE KEYSPACE "FridgeItems_system";with a result:
CREATE KEYSPACE "FridgeItems" WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1: '3', 'dc2' : '3'}
AND durable_writes = true;
CREATE KEYSPACE "FridgeItems_system" WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1: '3','dc2' : '3'}
AND durable_writes = true;