Eike Cochu
Eike Cochu

Reputation: 3429

Cassandra/NoSQL newbie: the right way to model?

as the title says I am fairly (read: completely) new to NoSQL DBS such as Cassandra. As many others, I learned RMDBS before. So I did a little reading on 'WTF is a super column' and other obvious google hits, but I am still not sure how to model this:

Say I want to save Users, as in username/password/name/etc... what if that user has like, a mobile phone and a landline telephone? is this the 'right' way to do it? (using the same abbreviated JSON style as seen on other sites)

Users: {    // <-- this is the Users SuperColumnFamily, keyed by username
    myuser: {    // <-- this is a User SuperColumn
        username = "myuser",    // <-- this is the username Column
        email = "[email protected]",
        ...
    },
    ...
}

Phone: {    // <-- this is where the users phone numbers are stored
    myuser: {
        mobile = "0129386835235",
        landline = "123876912384",
    },
    ...
}

opinions/corrections please

Upvotes: 2

Views: 945

Answers (1)

nickmbailey
nickmbailey

Reputation: 3684

First things first, don't use super columns. See:

http://www.quora.com/Cassandra-database/Why-is-it-bad-to-use-supercolumns-in-Cassandra

Now to answer your question. The example you described is easily modeled with just a regular column family:

Users: { <- This is the name of the column family
  username1: { <- this is a row key within the column family, it is one of your usernames
    email: [email protected] <- these are all of the columns within this row, they correspond to attributes for this user
    mobile: ...
    landline: ...
  }
  username2: { <- another row for a different user
    email: [email protected]
  }
}

You can see the flexible schema above in that each row has a different set of columns for describing that user.

For more info on the cassandra data model I would recommend reading over http://www.datastax.com/docs/1.0/ddl/index

Upvotes: 4

Related Questions