Storing Directory Hierarchy in a Key-Value Data store

前端 未结 4 1401
一个人的身影
一个人的身影 2020-12-12 12:57

What is a clean/efficient method for storing the directory Hierarchy/tree in a Key-Value database (in my case MongoDB but any of them)?

For example a tree structure

4条回答
  •  时光说笑
    2020-12-12 13:51

    I don't have a huge amount of NOSQL experience, so this isn't a definitive answer, but here's how I'd approach it:

    I would likely use your first approach, where you have:

    {
      dir: 'dir_name',
      parent_dir: 'parent_dir_name'
    }
    

    And then set up a map-reduce to quickly query the children of a directory. MongoDB's map-reduce functionality is still only available in the development branch and I haven't worked with it yet, but in CouchDB (and I assume, with a few modification, in MongoDB) you could do something like:

    map:
    function(doc) {
      emit( doc.parent_dir, doc.dir );
    }
    
    reduce:
    function(key, values) {
      return( values );
    }
    

    Which would give you the list of sub-directories for each parent directory.

提交回复
热议问题