0

I'm getting a 409 on PUT, POST and DELETE actions.

I have successfully created a database and have PUT one document successfully ONCE. I have tried local and "normal" documents. I haven't spend any focus on revisions but think it has to do with this. I only want to save and update this one JSON string in my app - thats it.

It's like I have created this one document to stay forever :-)

Will sample code help? I'm really only using Angular's $http.

On a side note: I need a save mechanism in phonegap that is html5 cache-clear resistent.

Matthias Max
  • 595
  • 1
  • 7
  • 20

1 Answers1

0

You need to check if your document exists first before you update it. that's why it worked the first time and not the second.

config.db.get( "myDocumentID", function(error, doc) {
    if (error) {
        if (error.status == 404) {
             //document does not exist insert it
             config.db.put( "myDocumentID", myDocument, function(error,ok) {
                 if(error) { alert( "error" + JSON.stringify( error ) } else {
                      alert("success");
                 }
             } )
        } else {
             alert( "error:" + JSON.stringify( error ) ) 
        }
    } else {
        //update your document
        doc.my_new_key = "value";
        config.db.put( "myDocumentID", doc, function(error, ok) {
            if( error ) { alert( "error:" + JSON.stringify( error ) ) } else {
                 alert("success");
            }
        } );
    }
} ) 
deefactorial
  • 293
  • 1
  • 12