Reputation: 792
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..
Upvotes: 7
Views: 403
Reputation: 3859
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.
Upvotes: 2