Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 16526 invoked from network); 23 Jun 2010 17:30:09 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Jun 2010 17:30:09 -0000 Received: (qmail 62044 invoked by uid 500); 23 Jun 2010 17:30:08 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 61997 invoked by uid 500); 23 Jun 2010 17:30:07 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 61989 invoked by uid 99); 23 Jun 2010 17:30:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jun 2010 17:30:07 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.68.5.15] (HELO relay01.pair.com) (209.68.5.15) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 23 Jun 2010 17:30:00 +0000 Received: (qmail 61074 invoked from network); 23 Jun 2010 17:29:38 -0000 Received: from 74.1.186.35 (HELO ?10.0.1.205?) (74.1.186.35) by relay01.pair.com with SMTP; 23 Jun 2010 17:29:38 -0000 X-pair-Authenticated: 74.1.186.35 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1078) Subject: Re: A question about attachments, stubs, and revpos From: Damien Katz In-Reply-To: Date: Wed, 23 Jun 2010 10:29:38 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <7F4EEA33-2F69-447F-8B7C-EDCEB8EA643E@apache.org> References: To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1078) On Jun 23, 2010, at 10:24 AM, Caleb Land wrote: > I'm writing a CouchDB library for ruby (who isn't these days :)), = partly for > my own use, and partly to teach myself about how couch works, and play = with > some ideas I have about working with it. >=20 > I've begun to implement attachments, and I'm a bit stuck about how to = go > forward. >=20 > Basically, I want to know how I can: >=20 > 1) GET a document and store it in an object > 2) PUT an attachment to that document > 3) PUT that document with revised fields >=20 > The problem is, when I PUT the attachment, the document is updated and = the > new document rev is returned. I can easily stuff this rev into the = _rev > field of my local document (like everyone does when they PUT a = document... > so subsequent PUTs use the correct _rev), but the problem comes when I = need > to PUT the document, and that document doesn't have the stub for the = newly > uploaded attachment. >=20 > I asked this question on IRC and got a reasonable answer back: Don't = modify > a document twice in a row without fetching it in between. >=20 > This makes sense, but then I thought about how when we save documents, = we > update our local copy's _rev with the rev returned by the server so we > wouldn't have to fetch it again. >=20 > Also, if the local document has some other fields that have changed = (let's > say so that we could do validation before uploading the attachments), = then > we have problems. >=20 > I can see two options to handle this: >=20 > 1) fetch the document again and grab the _attachments and find the new > attachment and merge it in with the local document >=20 > 2) build a stub and inject it into the local document: > { > 'stub': true, > 'revpos': parseInt(return_from_attachment_put['rev']) // * > } I'd use the second option, though I'm pretty sure you don't need the = revpos for a stub, so just leave that out and it should be fine. -Damien >=20 > * I'm not sure about this, since I didn't see a formal definition for > 'revpos' anywhere, but this seems to be how it works >=20 > My question is, what would an experienced CouchDB developer do in this > situation? >=20 >=20 > --=20 > Caleb Land