开发者

Related objects in 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

  ParentCateg开发者_运维百科oryId

  Name

or something of that nature..


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜