开发者

NoSQL and Atomicity / Normalization

开发者 https://www.devze.com 2023-04-04 14:12 出处:网络
I have experience with relational databases where atomicity and normalization are fundamental principles.

I have experience with relational databases where atomicity and normalization are fundamental principles.

D开发者_开发知识库o 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?


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.


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.


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 a fr 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消