user5492949
user5492949

Reputation: 53

Update single field in CouchDB

I want update one field in a document. I created a new document:

My new document

And I would like to change the value of field name from aaa to test. I copied a script from: wiki.apache.org/couchdb/Document_Update_Handlers, and I created a new design document:

New design document

Next I created a URL:

localhost:5984/asd/_design/temp/_update/in-place-query/8d6257096bbb199a3757954c00000d0c?name=title&value=test

That should update my field. I instead saw the error:

"{"error":"TypeError","reason":"{[{<<\"message\">>,<<\"point is undefined\">>},\n  {<<\"fileName\">>,<<\"../share/couchdb/server/main.js\">>},\n  {<<\"lineNumber\">>,1500},\n  {<<\"stack\">>,\n   <<\"(\\\"_design/temp\\\",[object Array],[object Array])@../share/couchdb/server/main.js:1500\\n()@../share/couchdb/server/main.js:1562\\n@../share/couchdb/server/main.js:1573\\n\">>}]}"}"

Have you got any idea to repair it?

Upvotes: 1

Views: 2096

Answers (2)

Ronnie Smith
Ronnie Smith

Reputation: 18585

Document updates require that you send the _rev id which means that you must have read the document prior. So, all you do is set the value of whatever document object property then pass the pre-read document back to couch in a PUT w _rev for updating.

Upvotes: 0

Suhas
Suhas

Reputation: 1471

Your update handler design doc should be in the form:

{
    "_id": "_design/app",
    "updates": {
        "accumulate": "function (doc, req) { // Your code here }"
    }
}

For further information, please checkout this SO post.

Let me know if this helps !

Upvotes: 1

Related Questions