正如标题所说,我对 NoSQL DBS(例如 Cassandra)相当(读作:完全)陌生。和其他许多人一样,我以前学过 RMDBS。所以我读了一点关于“WTF 是一个 super 专栏”和其他明显的谷歌点击,但我仍然不确定如何对此进行建模:
假设我想保存用户,例如用户名/密码/姓名/等...如果该用户有手机和固定电话怎么办?这是“正确”的做法吗? (使用与其他网站相同的缩写 JSON 样式)
Users: { // <-- this is the Users SuperColumnFamily, keyed by username
myuser: { // <-- this is a User SuperColumn
username = "myuser", // <-- this is the username Column
email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c0115191f091e2c0b03030b0009010d0500420f0301" rel="noreferrer noopener nofollow">[email protected]</a>",
...
},
...
}
Phone: { // <-- this is where the users phone numbers are stored
myuser: {
mobile = "0129386835235",
landline = "123876912384",
},
...
}
请提出意见/更正
最佳答案
首先,不要使用 super 列。请参阅:
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: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbaea8bea99bbeb6bab2b7f5b8b4b6" rel="noreferrer noopener nofollow">[email protected]</a> <- 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: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="76121f101036131b171f1a5815191b" rel="noreferrer noopener nofollow">[email protected]</a>
}
}
您可以看到上面的灵活架构,每行都有一组不同的列来描述该用户。
有关 cassandra 数据模型的更多信息,我建议阅读 http://www.datastax.com/docs/1.0/ddl/index
关于nosql - Cassandra/NoSQL 新手 : the right way to model?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10132766/