NoSQL 和原子性/规范化
我有使用关系数据库的经验,其中原子性和规范化是基本原则。
这些原则也适用于 NoSQL 环境吗?
看看以下用不同语言(用 MongoDB 表示法)表示字符串的方法:
{
'name': 'label_hello',
'en' : 'hello world!',
'de' : 'hallo welt!',
'es' : 'hola mundo!'
}
或者
{
'name' : 'label_hello',
'values': {
'en' : 'hello world!',
'de' : 'hallo welt!',
'es' : 'hola mundo!'
}
}
与更原子的变体相比:
{
'name' : 'label_hello',
'lang' : 'en',
'value': 'hello world!'
}
{
'name' : 'label_hello',
'lang' : 'de',
'value': 'hallo welt!'
}
{
'name' : 'label_hello',
'lang' : 'es',
'value': 'hola mundo!'
}
这些设计中哪一个在 NoSQL 世界中是最佳的?
更新:
为了进一步澄清我的问题:
我想知道/理解以下内容:这些变体中哪些变体会更快地查找、更容易更新、增加点击率、哪些变体可以更智能地建立索引?
I have experience with relational databases where atomicity and normalization are fundamental principles.
Do these principles also apply in a NoSQL environment?
Look at the following ways of representing a string in different languages (in a MongoDB notation):
{
'name': 'label_hello',
'en' : 'hello world!',
'de' : 'hallo welt!',
'es' : 'hola mundo!'
}
or
{
'name' : 'label_hello',
'values': {
'en' : 'hello world!',
'de' : 'hallo welt!',
'es' : 'hola mundo!'
}
}
vs. the more atomic variant:
{
'name' : 'label_hello',
'lang' : 'en',
'value': 'hello world!'
}
{
'name' : 'label_hello',
'lang' : 'de',
'value': 'hallo welt!'
}
{
'name' : 'label_hello',
'lang' : 'es',
'value': 'hola mundo!'
}
Which of these designs would be the most optimal in a NoSQL world?
Update:
To clarify my question further:
I'd like to know/understand stuff like: Which of these variants will be faster to seek, easier to update, increase hits, which can be indexed more intelligently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第二个变体运行速度更快,但第一个变体占用的内存更少。
在第一个变体中,“名称”值的重复次数较少,因此我会选择第一个变体,因为我不喜欢重复。
Second variant will work faster, but first variant will take less memory.
And in first variant we have less repeats of "name" value, so I'd choose first variant because I don't like repeats.
我是 NoSQL 新手,但根据我使用 Redis 等实用程序的经验,我可以建议,对于索引最后一个变体是最好的。其次是紧凑,所以它主要是开发人员的选择。并非所有事情都能始终处于原子性和规范化框架内,有时应该超越。
I'm new to NoSQL, but based on my experience with such utility like Redis I can suggest, that for indexing the last variant would be best. Second is compact so it's mostly the developer choise. Not all the time everything can be in atomicity and normalization frame, sometimes it should be beyond.
你不是说标准化而不是原子性吗?就关系而言,顶部是
(name,en,de,es)
,底部是(name,lang,value)
,后者允许人们添加其他语言而不添加列,但在文档形式中添加列就可以了,因此(name,en,de,es)
可以扩展为(name,en,de,es,fr)< /code> 没有问题,因为文档没有
fr
值在那里没有任何价值。但如果你真正指的是原子性,大多数文档系统只允许原子地更新单个文档,因此人们希望将值组合到可能同时更改的单个文档中。
don't you mean normalization not atomicity? what you have at the top is
(name,en,de,es)
and at the bottom(name,lang,value)
in terms of relations the later allows one to add additional languages without adding columns but in document form adding columns is fine so(name,en,de,es)
can be extended to(name,en,de,es,fr)
with no problem as the documents that don't have afr
value will have no value there.but if you really mean atomicity, most of the document systems only allow one to atomically update a single document, so one would want to group values together into a single document that are likely to be changed at the same time.