couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Go Hori>
Subject Emulating S3 path convention
Date Tue, 11 Oct 2011 15:45:41 GMT

I see a few references to implementing S3 like naming convention in
which an id contains a delimiter and an application can emulate
directory lookup using 'prefix' and 'delimiter' search parameters.
Has anyone done something like this with couch?

I have implemented a view with a map function that breaks down a path
and using startkey/endkey, I can get a list of ALL documents for a
given prefix.  That was pretty straight forward, but now I am stuck
trying to figure out how to support 'delimiter' part.  To start, I am
planning on a fix delimiter '/'.  So, please let me illustrate:

Let's assume we have five documents with following ids:
/beer   (without a trailing slash)
/sake  (without a trailing slash)

My mapper emits (key : value)
for the first doc
'/' : 'beer/'
'/beer/' : 'japan/'
'/beer/japan/' : 'asahi'

for the second doc
'/' : 'beer/'
'/beer/' : 'japan/'
'/beer/japan' : 'kirin'

for the last doc
'/' : 'sake'

So, If I do startkey="/beer/"&endkey="/beer/", I get

This makes sense.  I am getting all documents that contains a key "/beer/".

Now, with prefix & delimiter search, I'd like to return a list of
direct descendant of a path being searched without duplicates.
So, I want to return something like
"/beer/" => ["japan/", "usa/"].
Then, I can iterate through this list and traverse down a tree.

It feels like I should be able to reduce a map result down so that
it'll do what I want, but I am very much stuck..I tried to reduce map
results down to a list of unique values, but I cannot figure out how
to restrict the search so that it does what I want.

Any help will be greatly appreciated.


View raw message