couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hahn <m...@hahnca.com>
Subject Re: Exist test?
Date Mon, 05 Nov 2012 19:50:24 GMT
You can use an update handler.  It works with non-existent docs.  It's a
very clean way to do it that I use.

On Mon, Nov 5, 2012 at 11:45 AM, Robert Newson <rnewson@apache.org> wrote:

> Easiest to just create the document, you'll get a 409 response to indicate
> that it already existed. If your documents don't have user assigned id's,
> then I don't see how you could check for existence before writing anyway.
>
>
> On 5 November 2012 19:40, Kevin Burton <rkevinburton@charter.net> wrote:
>
> > I am mainly using it the context of initially populating a database. So
> > there isn't any danger of a race because there is only one user.
> >
> > On Nov 5, 2012, at 12:47 PM, Jens Alfke <jens@couchbase.com> wrote:
> >
> > >
> > > On Nov 5, 2012, at 10:22 AM, Kevin Burton <rkevinburton@charter.net>
> > wrote:
> > >
> > >> I am calling CreateDocument<Document>() but I suspect that testing
if
> > the document exists first may perform better in the long run. I am using
> > DreamSeat for my driver but I suspect other drivers have a similar
> "test".
> > My problem is that I don't know what to test for and I am unfamiliar with
> > the available methods. Any one successfully use such a pattern
> (preferably
> > with DreamSeat) that tests for existence then creates if the document
> > doesn't exist? Keep in mind I don't initially have an id. Thank you.
> > >
> > > I don’t know anything about that particular API, but in general,
> > check-then-create doesn’t work well in a concurrent environment. It’s
> prone
> > to race conditions where something else creates the resource in between
> > your check call and your create call. (The canonical example is checking
> > whether a file exists, then creating the file, which is a classic old
> > security hole in privileged Unix tools.)
> > >
> > > —Jens
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message