couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <>
Subject Re: Exist test?
Date Mon, 05 Nov 2012 19:45:47 GMT
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 <> 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 <> wrote:
> >
> > On Nov 5, 2012, at 10:22 AM, Kevin Burton <>
> 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

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