mirror of
https://github.com/jo/couchdb-best-practices.git
synced 2026-05-15 14:16:00 -06:00
[GH-ISSUE #54] What is the optimal and/or recommended way to store Hierarchical data on CouchDB #232
Labels
No labels
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/couchdb-best-practices#232
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jofomah on GitHub (Jun 24, 2015).
Original GitHub issue: https://github.com/jo/couchdb-best-practices/issues/54
This should make it easy and possible to do the following in one request:
@jofomah commented on GitHub (Jun 27, 2015):
Possible Answer:
i think i have found something that can work on CouchDB, i looked into patterns used to store hierarchical data on relational database
in this case, i will just store each document's ancestors as an array property of the document
this is similar to @jo's suggestion to emit ([country, national level, state], doc), the only difference is that i won't have to store the ancestor as string property of the document e.g doc.stateId, doc.wardId, doc.lgaId but as array of ancestors i can use administrative levels not tied to any country's administrative level names.
but in this case, i will just emit each ancestor array element as key
if i now query with key = stateId, where stateid = 'KN', i will be able to get all state sub-levels that has 'KN' as one of their ancestors, which what the current adjacent list am using could not give me. (edited)
@jo commented on GitHub (Jun 29, 2015):
This is a good solution. I recommend to emit the whole
ancestorsarray:This has two advantages over using one view per level:
But also a disadvantage:
If you now want to get a list of all docs in state
KNyou query for the full path:The same view returns all documents for a higher level: