Connect to cassandra without the key space name

110 views
Skip to first unread message

Bhavesh Joshi

unread,
Nov 15, 2017, 4:22:56 AM11/15/17
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hi,
I am using the cassandra-driver 

to create a connection to the driver it is using 

const client = new cassandra.Client({ contactPoints: ['h1', 'h2'], keyspace: 'ks1' });

Is is possible to connect to it without key space ?
I want to check if the keyspace exist otherwise create it.

and also can I use an url in contactPoints instead of the ip?

which is the url to cassandra on ec2 instance.

Jorge Bay Gondra

unread,
Nov 15, 2017, 6:28:34 AM11/15/17
to nodejs-dr...@lists.datastax.com
Hi,
You can create a Client instance without setting the keyspace.
You can create it afterwards and either, use fully qualified table names, ie: "ks1.table1" or switch keyspace:

client.connect()
  .then(() => client.execute("CREATE KEYSPACE IF NOT EXISTS ks1 ..."))
  .then(() => client.execute("USE ks1"))
  .then(() => /* from this moment on, your connections are using the ks1 keyspace */);

Also, you can use the host name instead of the IP address, the driver will resolve the IP internally.

Hope it helps,
Jorge

--
You received this message because you are subscribed to the Google Groups "DataStax Node.js Driver for Apache Cassandra Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.

Bhavesh Joshi

unread,
Nov 15, 2017, 12:30:22 PM11/15/17
to DataStax Node.js Driver for Apache Cassandra Mailing List
Thanks 
Reply all
Reply to author
Forward
0 new messages