node-couchdb icon indicating copy to clipboard operation
node-couchdb copied to clipboard

Call update function with POST/PUT body

Open kylechine opened this issue 7 years ago • 4 comments

Hello 1999,

Thanks for your work. It's very elegant and helpful.

I'm a little bit confuse about this problem:

couch.updateFunction("databaseName", "designDocument", "updateFunction", {optional query string}, "docid")

URL query parameters object. Note that multiple keys are not supported and the last key value suppresses others. From CouchDB document - Request Object

So does this means {optional query string} could have only one key-value pair? If there any plan to add method to submit POST/PU body with this function?

Thank you again.

kylechine avatar May 01 '18 06:05 kylechine

Thank you for your kind words. This part is contributed by @bgardner87 so hopefully he knows more about this.

1999 avatar May 01 '18 10:05 1999

@winfredkqin It's been a while since I've looked at it, but it appears it's a limitation in the CouchDB api so there isn't much to be done here in this library. I think if you need to make use of multiple query parameters, you may have to use multiple requests but that may or may not work for your use case.

bgardner87 avatar May 01 '18 16:05 bgardner87

@bgardner87 Thanks for your reply.

When the request to an update handler includes a document ID in the URL, the server will provide the function with the most recent version of that document. You can provide any other values needed by the update handler function via the POST/PUT entity body or query string parameters of the request.

CouchDB - Update Functions

It seems CouchDB doc encourages developers to use POST/PUT body rather than query parameter. I think maybe pass JSON via HTTP body could be a better approach.

kylechine avatar May 01 '18 22:05 kylechine

@winfredkqin I agree, the update function in this api could probably be updated to allow using post/put body as well as query string. It sounds like it would be a good add to me.

bgardner87 avatar May 02 '18 17:05 bgardner87