incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <...@jsonified.com>
Subject Re: Choosing Document IDs
Date Mon, 05 Aug 2013 12:17:43 GMT
On 5 August 2013 11:08, Oliver Schmidt <spiollinux@googlemail.com> wrote:
> I'm building a couchapp for collecting recipes with kanso. How shall I choose the document
IDs? Using a slug of the recipe name would create nice URLs but how can I prevent recipes
with the same name from colliding (there might be more than one recipe for apple pie)? Shall
I use UUIDs instead?
>
> Regards Oliver

+1 to the other comments.

Anyway, unless your recipes DB is enormous the uuid you choose won't
matter -- optimise for simplicity :-).

I'd probably do this:

# get some uuids for new recipes
GET /_uuids?count=5

PUT /recipes {_id: "one_of_those_uuids", "name": "apple pie", ….}

and then in your view, emit(doc.name) and voila you will have a view
containing all the "apple pie" recipes. The doc id is always available
within view results, so its not needed to emit that specifically.

The reason for GETing a bunch of uuids first is to avoid POSTing data
without a UUID and not being sure what to do if the transaction
doesn't complete - should you resubmit, does the db already have the
recipe but network lost the 200 OK along the way? etc etc.

You might want to use rewrites to make pretty urls - look at
docs.couchdb.org for some examples.

I know a few other folk are doing recipe stuff so perhaps they will
spill their secret sauces too.
A+
Dave

Mime
View raw message