Cassandra/NoSQL newbie: the right way to model?

2019-05-23 05:37发布

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 = "myuser@googlemail.com",
        ...
    },
    ...
}

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

opinions/corrections please

1条回答
做个烂人
2楼-- · 2019-05-23 06:37

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: user@email.com <- 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: diff@email.com
  }
}

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

查看更多
登录 后发表回答