How to perform CRUD opearation on Cassandra using CQLSH

This article will show the useful commands to perform CRUD operation on Cassandra using CQLSH. 1) Insert the data Syntax is: insert into <TABLE_NAME>(COLUMN1, COLUMN2) values (VALUES1, VALUES2); The table structure to insert the data is: CREATE TABLE cassandrademo.users ( user_id int PRIMARY KEY, user_email text, user_name text, user_pwd text ) Use the following command […]

How to truncate a table in Cassandra using CQLSH

Syntax for truncating a table/columnfamily is : TRUNCATE <TABLE_NAME | COLUMN_FAMILY_NAME> Using this command will delete all the rows from the table/columnfamily. Let’s say the data in our table is: select * from users; Output: user_id | user_email | user_name | user_pwd ———+————–+———–+———- 1 | | user1 | pwd1 To truncate all the data […]

How to alter a table in Cassandra using CQLSH

Syntax for altering table/columnfamily is: ALTER TABLE <TABLENAME> <OPEARTION> or ALTER COLUMNFAMILY <TABLENAME> <OPEARTION> Below example is given for adding a column in the table. alter table cassandrademo.users add user_phone text; Verify the table structure by using: describe table users; Output: CREATE TABLE cassandrademo.users ( user_id int PRIMARY KEY, user_email text, user_name text, user_phone text, […]

How to create Columnfamilies or Tables in Cassandra using cqlsh

Syntax for creating a table/columnfamily is: CREATE TABLE <TABLE_NAME> ( ‘column-definition’, ‘column-definition’, ) (WITH <OPTION> AND <OPTION>) or CREATE COLUMNFAMILY <TABLE_NAME> ( ‘column-definition’, ‘column-definition’, ) (WITH <OPTION> AND <OPTION>) Syntax for defining a column in the table is: column_name column_data_type Example to create a table is given below: create table cassandrademo.users( user_id int Primary Key, […]

How to create Keyspace in Cassandra

In this example I am referring Cassandra 2.1.5 version Creating a keyspace Use the following to create a keyspace create keyspace cassand with replication={‘class’:’SimpleStrategy’, ‘replication_factor’:3} and durable_writes=true Here class attributes indicates the replication strategy. 3 types are strategies are applicable: Simple Strategy – Provides simple replication for the cluster. Network Topology Strategy – Each data-center […]


How to install DataStax DevCenter on MacOS for Cassandra

1) Go the dowload page of DataStax 2) Go bottom down the page and select DEVCENTER Visual Query Tool. 3) Select 64 bit for MacOS. It will start downloading. 4) Extract the file contents tar -xzvf Documents/DevCenter-1.3.1-macosx-x86_64.tar.gz 5) Go to the extracted folder and click on DevCenter icon to launch. 6) The DevCenter window […]

How to install Cassandra on MacOS

1) Download the Apache Cassandra from the below provided link this example I am referring Cassandra 2.1.5 verison.2) Now unzip the folder by using command: tar -xzvf $PATH/apache-cassandra-2.1.5-bin.tar.gz It will extract the tar file in the folder. 3) All the logs will go in the log folder which is configured by conf/logback.xml ~/cassandra/logs 4) […]

How to create user in MongoDB

Below are the steps by which a user can be created for a database in MongoDB 1) switch to your database on which the user needs to be created for granting access > use demodb 2) Create user on this database > db.createUser({user:’user1′, pwd: ‘pwd1′, roles:[{role:’readWrite’, db:’demodb’}]}) this will add a user for demodb in […]