So the update handler sets some global variable indicating that the document already exists? How do I tell that the update handler has run to completion?
On Nov 5, 2012, at 1:50 PM, Mark Hahn <[email protected]> wrote: > 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> wrote: >>> >>>> >>>> On Nov 5, 2012, at 10:22 AM, Kevin Burton <[email protected]> >>> 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 >>
