Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:22:53+00:00 2026-05-28T14:22:53+00:00

How to store a tree in CouchDB? The CouchDB Wiki has a How_to_store_hierarchical_data page

  • 0

How to store a tree in CouchDB?

The CouchDB Wiki has a How_to_store_hierarchical_data page that describes a method, but the author says about moving nodes:

This part worries me a bit, because there’s a chance that somebody
else could add a new child node while you are in the process of moving
the sub-tree, leaving that new node dangling by itself in a sub-tree
which no longer exists. I’m not sure of the best approach to avoid
such a problem.

With such a big problem, is this really the best practice for storing trees?

I am thinking of implementing my tree by adding a parentId to each node, is it bad?

(I realize it is similar to this question, but the accepted answer there has unspecified behavior when moving nodes)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:22:54+00:00Added an answer on May 28, 2026 at 2:22 pm

    This is something I’ll be solving for BlueInk soon. Currently I’m using a materialized path and plan to use MapReduce to generate sitemap (the full tree) dynamically.

    When moving branches of the tree it may be best to do a Bulk Update with “all_or_nothing: true”:

    However…

    all-or-nothing – To use this mode, include all_or_nothing: true as
    part of the request. In the case of a validation failure, none of the
    documents will be saved. However, it does not do conflict checking, so
    all documents will be committed even if this creates conflicts.

    …so you’d potentially end up with conflicts and you’d have to make sure your validate_doc_update didn’t prevent the change entirely.

    Another alternative would be to be “eventually consistent” with the change. You could do a Bulk Update without all_or_nothing, and continue to process each item in the MapReduce results via your client code until they’re all moved. That’s likely quite risky, though, given that someone may want to move it back, etc.

    Regardless of the approach keeping a history of it’s former location may be prudent in case something goes wrong.

    The only trouble I see with parent_id is the number of requests you’ll need to build the full path to the item. Though it might be possible to use a _list in addition to some simple MapReduce results that use a [parent_id, _id] key. Building the _list function would be none trivial, but should be doable.

    I’ve tested some of these approaches, but I don’t yet have it completely fleshed out. If you make it farther down any of these paths, I’d love to hear about your progress/findings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For dynamic programming, what are some of the ways that I store a tree
I have a tree with n elements that store something like |id|parent_id| . I
I'm trying to make an application that can store a tree structure with files
I want to store the following input in a tree such that a number
I have a hobby project which is about creating a tree to store identification
I have a dijit.Tree backed by a ForestStoreModel that uses a custom data store
Is there a DB out there that can store tree structures (like for nested
Suppose I have a table nodes where I store a tree. Each node has
I need to store a tree data structure in my database, for which I
How do i store a directory / hierarchy / tree structure in the database?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.