2

正如标题所说,我对 NoSQL DBS(如 Cassandra)相当(阅读:完全)新手。和其他许多人一样,我之前学过 RMDBS。所以我读了一些关于“WTF 是一个超级专栏”和其他明显的谷歌热门文章,但我仍然不确定如何建模:

假设我想保存用户,如用户名/密码/姓名/等...如果该用户喜欢手机和固定电话怎么办?这是“正确”的做法吗?(使用与在其他网站上看到的相同的缩写 JSON 样式)

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",
    },
    ...
}

请提出意见/更正

4

1 回答 1

4

首先,不要使用超级列。看:

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

现在回答你的问题。您描述的示例很容易使用常规列族进行建模:

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
  }
}

您可以看到上面的灵活模式,因为每一行都有一组不同的列来描述该用户。

有关 cassandra 数据模型的更多信息,我建议您阅读http://www.datastax.com/docs/1.0/ddl/index

于 2012-04-12T23:02:20.533 回答