Cassandra / NoSQL newbie:正确的方式来模型? [英] Cassandra/NoSQL newbie: the right way to model?
问题描述
作为标题说我公平(读:完全)新的NoSQL DBS,如Cassandra。和许多其他人一样,我以前学过RMDBS。所以我对'WTF是一个超级列'和其他明显的谷歌点击,但我仍然不知道如何建模一个小的阅读:
说我想保存用户,如在用户名/密码/名称/ etc ...如果用户喜欢,手机和固定电话怎么样?这是正确的方式吗? (使用与在其他网站上看到的相同的缩写JSON样式)
用户:{//< SuperColumnFamily,用户名为
myuser:{//< - 这是一个用户超级列
username =myuser,//< - 这是用户名列
email = myuser@googlemail.com,
...
},
...
}
电话:{//<这是用户电话号码存储的位置
myuser:{
mobile =0129386835235,
landline =123876912384,
},
...
}
意见/更正请
http://www.quora.com/Cassandra-database/Why-is-it-bad-to-use-supercolumns-in-Cassandra
现在回答你的问题。您描述的示例很容易使用常规列系列建模:
用户:{&列族
username1:{< - 这是列系列中的一个行键,它是您的用户名之一
email:user@email.com< - 这些都是此列中的所有列行,它们对应于此用户的属性
mobile:...
landline:...
}
username2:{< - 不同用户的另一行
email:diff@email.com
}
}
请参阅上面的灵活模式,因为每行都有不同的列来描述该用户。
有关cassandra数据模型的更多信息,我建议阅读 http://www.datastax.com/docs/1.0/ddl/index p>
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
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
这篇关于Cassandra / NoSQL newbie:正确的方式来模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!