Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update denormalized duplicated data

Tags:

mongodb

nosql

Trying to migrate from RDBMS to NOSQL ( to be specific MongoDB). So couple of things that i've got so far:

1) Denormalization is ok for nosql

2) Data duplication is ok.

So i'm puzzled with duplicated data update...

Let's imagine we have cars and boats. They have common color property. Then we decided to rename color. We don't want to use "Red", we want to use "Bright red" instead.

RDBMS case: So for example in RDBMS i will have three tables : car, boat, color. Car and Boat have foreign keys linked to Color table. I'll update only one table with one query and get consistent data.

NOSQL case: I have two collections... Boats and Cars. We have color field for each document. E.g. Boat { color:"red", type:"fast" }

Car{ color:"red", type:"slow" }

So when i want to change color name, i should run two queries (for each collection) and update each document where color == "red"? But what if i have dozens of collections with duplicates and could FORGET one of them? Is there any common approach/DB design to avoid/ease cope with such cases? Or this is one of nosql trade offs?

like image 467
Ivan Lymar Avatar asked Nov 09 '22 07:11

Ivan Lymar


1 Answers

1) Denormalization is ok for nosql

While indeed it is ok for nosql it may be not ok for your particular project. When you decide what to use sql or nosql you should weight the pros and cons.

2) Data duplication is ok.

this is mostly consequence of denormalization, so all the same applicable here.

like image 130
talex Avatar answered Nov 15 '22 14:11

talex