couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Re: Moving an attachment from one document to another
Date Sun, 19 Apr 2009 17:35:54 GMT
On Sun, Apr 19, 2009 at 06:49:03PM +0200, Wout Mertens wrote:
>
> On Apr 19, 2009, at 12:26 AM, Justin Walgran wrote:
>
>> Making a separate doc per file from the get go, per Chris's
>> suggestion,  is not a problem but how can I change the doc ID to
>> something more meaningful after the doc is added?
>
> You can't. You'll have to create a new document and delete the old one.

But you *can* just have a name attribute, and you index it in a view:

{
  "name":"anything you like",
}

// MAP
function(doc) {
  if (doc.name) { emit(doc.name, null); }
}


The only reason you'd want to use the docid for the 'meaningful' name is to
enforce uniqueness of this name. However even that isn't enforced if you use
multi-master replication (i.e. you can end up with two "versions" of a
document under the same name, and one will effectively vanish unless you ask
for it explicitly)

So you might as well just let the user choose a name, doing a search for it
first to check that it hasn't been taken. In the (very rare) case where a
race condition ends up with two documents having the same name, this is very
easy to highlight to the user, and it's also very easy to let them choose
which one they want to see.

Regards,

Brian.

Mime
View raw message