You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Justin Walgran <jw...@gmail.com> on 2009/04/18 18:02:18 UTC
Moving an attachment from one document to another
Does couch provide a way to _atomically_ move an attachment between documents?
My proposed use case for this feature is for scanning paper documents,
then splitting them into individual couch documents afterward. Here is
a rough list of steps:
- Create a document with the ID 'newscans'
- Have a desktop application POST image files (acquired from a scanner
with a sheet feeder) to the 'newscans' document one after another as
attachments.
- To process the batch of scanned images, have the user create a new
couch document, moves a single attachment from 'newscans' to the new
document ID, then add some metadata. Wash, rinse, repeat.
So..
1) Can this be done with the existing CouchDB trunk?
2) If not...
2a) Is there a better way?
2b) I am an experienced programmer but an erlang noob. At what
location in the code should I start exploring in order to develop a
patch.
- Justin Walgran
Re: Moving an attachment from one document to another
Posted by Justin Walgran <jw...@gmail.com>.
>There's only limited utility to human readable docids.
I agree, Chris. Better to give this up and "go with the grain" of
CouchDB. Thanks.
Re: Moving an attachment from one document to another
Posted by Brian Candler <B....@pobox.com>.
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.
Re: Moving an attachment from one document to another
Posted by Chris Anderson <jc...@apache.org>.
On Sun, Apr 19, 2009 at 12:49 PM, Wout Mertens <wo...@gmail.com> 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.
>
There's only limited utility to human readable docids. The benefit is
that you don't need a view to give easy access to the docs, the cost
is that you increase the chances of collisions. I'd just use the view,
as that's what they are for.
--
Chris Anderson
http://jchrisa.net
http://couch.io
Re: Moving an attachment from one document to another
Posted by Wout Mertens <wo...@gmail.com>.
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.
Wout.
Re: Moving an attachment from one document to another
Posted by Justin Walgran <jw...@gmail.com>.
>"But even if you keep your method, why does the attachment move need
>to be atomic?"
I was concerned about an attachment file being either duplicated or
lost if there was a 2-step PUT and DELETE.
>I'd suggest that for each scanned image create a new document. Then
>you can go back and add metadata at your own pace.
The trick I was hoping to pull off was to have someone in a mailroom
bulk scan the paper, then have someone 'upstairs' create documents
with meaningful doc IDs. For example, "invoice-020023" or "po-20332."
Also, a single scan operator with a high speed scanner can keep
several metadata collectors busy, maximizing throughput.
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? Having a
human-meaningful ID It is a convenience, for sure, but these paper
documents already have a perfect doc ID right on the page. It would be
a shame to have to generate another random GUID.
--
Justin Walgran
Re: Moving an attachment from one document to another
Posted by Chris Anderson <jc...@apache.org>.
On Sat, Apr 18, 2009 at 1:52 PM, Jan Lehnardt <ja...@apache.org> wrote:
>
> On 18 Apr 2009, at 12:02, Justin Walgran wrote:
>
>> Does couch provide a way to _atomically_ move an attachment between
>> documents?
>>
>> My proposed use case for this feature is for scanning paper documents,
>> then splitting them into individual couch documents afterward. Here is
>> a rough list of steps:
>>
>> - Create a document with the ID 'newscans'
>> - Have a desktop application POST image files (acquired from a scanner
>> with a sheet feeder) to the 'newscans' document one after another as
>> attachments.
>> - To process the batch of scanned images, have the user create a new
>> couch document, moves a single attachment from 'newscans' to the new
>> document ID, then add some metadata. Wash, rinse, repeat.
>>
>> So..
>>
>> 1) Can this be done with the existing CouchDB trunk?
>> 2) If not...
>> 2a) Is there a better way?
I'd suggest that for each scanned image create a new document. Then
you can go back and add metadata at your own pace.
>> 2b) I am an experienced programmer but an erlang noob. At what
>> location in the code should I start exploring in order to develop a
>> patch.
>
> How about:
>
> Creating new documents with an attribute "new":true, write a view that
> filters for "new":true docs and have users take scans from there. or
> directly add the meta data to these docs and then remove the new
> flag.
>
> But even if you keep your method, why does the attachment move need
> to be atomic?
>
> Cheers
> Jan
> --
>
>
--
Chris Anderson
http://jchrisa.net
http://couch.io
Re: Moving an attachment from one document to another
Posted by Jan Lehnardt <ja...@apache.org>.
On 18 Apr 2009, at 12:02, Justin Walgran wrote:
> Does couch provide a way to _atomically_ move an attachment between
> documents?
>
> My proposed use case for this feature is for scanning paper documents,
> then splitting them into individual couch documents afterward. Here is
> a rough list of steps:
>
> - Create a document with the ID 'newscans'
> - Have a desktop application POST image files (acquired from a scanner
> with a sheet feeder) to the 'newscans' document one after another as
> attachments.
> - To process the batch of scanned images, have the user create a new
> couch document, moves a single attachment from 'newscans' to the new
> document ID, then add some metadata. Wash, rinse, repeat.
>
> So..
>
> 1) Can this be done with the existing CouchDB trunk?
> 2) If not...
> 2a) Is there a better way?
> 2b) I am an experienced programmer but an erlang noob. At what
> location in the code should I start exploring in order to develop a
> patch.
How about:
Creating new documents with an attribute "new":true, write a view that
filters for "new":true docs and have users take scans from there. or
directly add the meta data to these docs and then remove the new
flag.
But even if you keep your method, why does the attachment move need
to be atomic?
Cheers
Jan
--