Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Related objects in CouchDB

Tags:

couchdb

I'm really trying hard to understand this new concept after working so long with relational databases...

Can anyone explain how I should go about storing say, a category hierarchy?

in a relational DB, I'd have:

Category:
  CategoryId
  ParentCategoryId
  Name

or something of that nature..

like image 934
Michael Baldry Avatar asked Feb 05 '10 22:02

Michael Baldry


1 Answers

You can start with the same approach as you would with relational databases: creating a separate document for each category, and keeping a reference to the parent category.

If you'd like to query a whole subtree or breadcrumbs with a single query, you should maintain an array field that contains all the ancestor keys. Then you can create a view that walks through the ancestors and emits [ancestor_key, doc] for querying a subtree. To get the breadcrumbs data for a category make a bulk query on the ancestor IDs.

like image 92
Leventix Avatar answered Oct 01 '22 20:10

Leventix