Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No-sql relations question

I'm willing to give MongoDB and CouchDB a serious try. So far I've worked a bit with Mongo, but I'm also intrigued by Couch's RESTful approach.

Having worked for years with relational DBs, I still don't get what is the best way to get some things done with non relational databases.

For example, if I have 1000 car shops and 1000 car types, I want to specify what kind of cars each shop sells. Each car has 100 features. Within a relational database i'd make a middle table to link each car shop with the car types it sells via IDs. What is the approach of No-sql? If every car shop sells 50 car types, it means replicating a huge amount of data, if I have to store within the car shop all the features of all the car types it sells!

Any help appreciated.

like image 621
pistacchio Avatar asked Feb 09 '10 17:02

pistacchio


1 Answers

I can only speak to CouchDB.

The best way to stick your data in the db is to not normalize it at all beyond converting it to JSON. If that data is "cars" then stick all the data about every car in the database.

You then use map/reduce to create a normalized index of the data. So, if you want an index of every car, sorted first by shop, then by car-type you would emit each car with an index of [shop, car-type].

Map reduce seems a little scary at first, but you don't need to understand all the complicated stuff or even btrees, all you need to understand is how the key sorting works.

http://wiki.apache.org/couchdb/View_collation

With that alone you can create amazing normalized indexes over differing documents with the map reduce system in CouchDB.

like image 79
mikeal Avatar answered Oct 25 '22 02:10

mikeal