gpt4 book ai didi

nosql - Cassandra/NoSQL 新手 : the right way to model?

转载 作者:行者123 更新时间:2023-12-04 18:23:55 25 4
gpt4 key购买 nike

正如标题所说,我对 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 = "myuser@googlemail.com",
...
},
...
}

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

关于nosql - Cassandra/NoSQL 新手 : the right way to model?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10132766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com